Created
January 20, 2015 19:27
-
-
Save will-clarke/1f733bc4ba1a63f0bd1a to your computer and use it in GitHub Desktop.
XKCD Scraper
This file contains 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 'mechanize' | |
require 'open-uri' | |
a = Mechanize.new | |
(1..20).each do |i| | |
page = a.get("http://xkcd.com/#{i}/") | |
leading_zeros = "%04d" % i | |
if page.parser.css('#comic') | |
image_url = page.parser.css('#comic').children[1].first[1].to_s | |
a.get( a.get(image_url) ).save_as "#{leading_zeros}-#{a.get(image_url).filename}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment