Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Save Facebook group photos to Downloads folder using Firefox and Selenium WebDriver
# 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
You can’t perform that action at this time.