Skip to content

Instantly share code, notes, and snippets.

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
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 =
profile = 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 "{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
@driver.find_element(:css, '[title="Next"]').click
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.