Created
April 18, 2013 21:48
-
-
Save Stephenitis/5416505 to your computer and use it in GitHub Desktop.
Stephen's home built image scrapper.
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 '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