Skip to content

Instantly share code, notes, and snippets.

@Stephenitis
Created April 18, 2013 21:48
Show Gist options
  • Select an option

  • Save Stephenitis/5416505 to your computer and use it in GitHub Desktop.

Select an option

Save Stephenitis/5416505 to your computer and use it in GitHub Desktop.
Stephen's home built image scrapper.
require 'rubygems'
require 'nokogiri'
require 'open-uri'
require 'uri'
puts "what website would you like to scrape?"
link = gets.chomp
URL = link
def make_absolute( href, root )
URI.parse(root).merge(URI.parse(href)).to_s
end
Nokogiri::HTML(open(URL)).xpath("//img/@src").each do |src|
uri = make_absolute(src,URL)
File.open(File.basename(uri),'wb'){ |f|p f.methods; f.write(open(uri).read) }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment