Skip to content

Instantly share code, notes, and snippets.

@hiru926
Created December 25, 2008 09:58
Show Gist options
  • Save hiru926/39876 to your computer and use it in GitHub Desktop.
Save hiru926/39876 to your computer and use it in GitHub Desktop.
$KCODE = "sjis"
require 'rubygems'
require 'hpricot'
require 'mechanize'
require 'open-uri'
require 'uri'
url = ARGV[0]
agent = WWW::Mechanize.new
doc = agent.get(url)
(doc/'script').each do |elem|
if elem.attributes['src'] then
if elem.attributes['src'] =~ /^http/ then
d = agent.get(elem.attributes['src'])
elsif elem.attributes['src'] =~ /^\// then
urlparse = URI.parse(url)
d = agent.get(URI.join(urlparse.scheme + '://' + urlparse.host, elem.attributes['src']))
else
d = agent.get(url + elem.attributes['src'])
end
puts "/******************** " + elem.attributes['src'] + " ********************/"
puts d.body
else
puts "/******************** html ********************/"
puts elem.inner_html
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment