Skip to content

Instantly share code, notes, and snippets.

@will-clarke
Created January 20, 2015 19:28
Show Gist options
  • Save will-clarke/5bd8b0f95eb6a46d3bd0 to your computer and use it in GitHub Desktop.
Save will-clarke/5bd8b0f95eb6a46d3bd0 to your computer and use it in GitHub Desktop.
C&H Scraper
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