Created
November 11, 2019 05:18
-
-
Save carlin-q-scott/3b559813285b3007b4e326453b34eece to your computer and use it in GitHub Desktop.
Save Facebook group photos to Downloads folder using Firefox and Selenium WebDriver
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This script will download all the photos owned by a group from Facebook. | |
require 'json' | |
require 'selenium-webdriver' | |
if ARGV.length != 3 | |
print "please provide all the command arguments: {facebook group id} {first photo to download, often '1'} {last photo to download}" | |
exit 1 | |
end | |
group_id = ARGV[0] | |
first_photo_to_download = ARGV[1] | |
last_photo_to_download = ARGV[2] | |
firefox_profile = Dir.glob(ENV.AppData + '\Mozilla\Profiles\*.default') | |
# Use my profile | |
options = Selenium::WebDriver::Firefox::Options.new | |
profile = Selenium::WebDriver::Firefox::Profile.new firefox_profile | |
profile['browser.helperApps.neverAsk.saveToDisk'] = 'image/jpeg;' | |
options.profile = profile | |
@driver = Selenium::WebDriver.for :firefox, :options => options | |
@driver.manage.timeouts.implicit_wait = 30 | |
def download_image | |
sleep 0.2 | |
@driver.find_element(:xpath, "//a[./*[text()='Options']]").click | |
sleep 0.2 | |
@driver.find_element(:xpath, "(//a[.//*[text()='Download']])[last()]").click | |
# @driver.find_element(:xpath, "//a[.//*[text()='Close']]").click | |
end | |
@driver.navigate.to "https://www.facebook.com/groups/#{group_id}/photos/" | |
@driver.find_element(:xpath, "(//div[@id='group_photoset']/table/tbody//a)[#{first_photo_to_download}]").click | |
(first_photo_to_download .. last_photo_to_download).each do | |
download_image | |
@driver.find_element(:css, '[title="Next"]').click | |
end | |
@driver.quit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment