Last active
July 21, 2021 17:00
-
-
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
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
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