Skip to content

Instantly share code, notes, and snippets.

@Andrew8xx8
Created November 19, 2014 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Andrew8xx8/84474222b7cb5fa51175 to your computer and use it in GitHub Desktop.
Save Andrew8xx8/84474222b7cb5fa51175 to your computer and use it in GitHub Desktop.
grabber.rb
require 'net/http'
require 'uri'
return p "wrong arguments" if ARGV.length < 2
url = ARGV[0]
dest_path = ARGV[1]
html = Net::HTTP.get(URI(url));
html.scan(/<img.*?src.*?['|"](http.*?)['|"]/).each do |match|
img_url = URI(match[0])
name = File.basename(img_url.path)
img = Net::HTTP.get(URI(img_url));
path = File.join(dest_path, name)
File.open(path, 'w') do |file|
p "Writing file #{path}"
file.write(img)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment