Skip to content

Instantly share code, notes, and snippets.

@satococoa
Created January 16, 2009 12:18
Show Gist options
  • Save satococoa/47908 to your computer and use it in GitHub Desktop.
Save satococoa/47908 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Webページからリンクされているjpg, gif, pngをカレントディレクトリにダウンロード
require 'rubygems'
require 'open-uri'
require 'nokogiri'
require 'uri'
urls = ARGV
urls.each do |url|
doc = Nokogiri::HTML(open(url))
doc.search('a[@href$=".jpg"]', 'a[@href$=".png"]', 'a[@href$=".gif"]').each do |link|
imguri = link.attributes['href'].to_s
filename = File.basename(URI.parse(imguri).path)
open(filename, 'w') {|f|
f.puts URI.parse(imguri).read
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment