Created
January 20, 2015 19:28
-
-
Save will-clarke/5bd8b0f95eb6a46d3bd0 to your computer and use it in GitHub Desktop.
C&H 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 | |
(41..50).each do |i| | |
page = a.get("http://www.explosm.net/comics/#{i}/") | |
# image_url = page.image.first.url.to_s | |
leading_zeros = "%04d" % i | |
if page.image_with(alt: "Cyanide and Happiness, a daily webcomic") | |
image_url = page.image_with(alt: "Cyanide and Happiness, a daily webcomic").url.to_s | |
a.get( a.get(image_url) ).save_as "#{leading_zeros}-#{a.get(image_url).filename}" | |
end | |
end | |
page.parser.css('#comic').children.search('img').to_s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment