Skip to content

Instantly share code, notes, and snippets.

@joseramonc
Last active July 21, 2021 17:00
Show Gist options
  • Save joseramonc/e3221b92b704403289f3733a6399edf9 to your computer and use it in GitHub Desktop.
Save joseramonc/e3221b92b704403289f3733a6399edf9 to your computer and use it in GitHub Desktop.
Ruby script to download all octocats images from the octodex. octodex.github.com
require 'nokogiri'
require 'open-uri'
BASE_URL = 'https://octodex.github.com'
DESTINATION_FOLDER = "/Users/joseramonc/src/images/octodex"
octodex = Nokogiri::HTML open BASE_URL
octodex.css('.preview-image').each do |preview|
absolute_path = preview.css('img')[0]['data-src']
file_name = absolute_path.split('/').last
IO.copy_stream(open("#{BASE_URL}#{absolute_path}"), "#{DESTINATION_FOLDER}/#{file_name}")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment