require 'net/http'
1.upto(99) do |novel|
puts "Downloading ##{novel}..."
Net::HTTP.start("http://www.nbc.com") do |http|
resp = http.get("/heroes/novels/downloads/Heroes_novel_0#{novel}.pdf")
open("Heroes_novel_#{novel}.pdf", "w") do |file|
file.write(resp.body)
end
end
puts "Next..."
puts
end
puts "Okay, Sneak it's done!"
当我运行我的脚本,我得到这些错误:下载列表 - 网/ HTTP
C:/Ruby192/lib/ruby/1.9.1/net/http.rb: 644:在
initialize': getaddrinfo: No such host is known. (SocketError) from C:/Ruby192/lib/ruby/1.9.1/net/http.rb:644:in
中打开来自C:/Ruby192/lib/ruby/1.9.1/net/http.rb:644的' :来自C:/Ruby192/lib/ruby/1.9.1/timeout的block in connect' from C:/Ruby192/lib/ruby/1.9.1/timeout.rb:44:in
超时' 。 rb:89:在timeout' from C:/Ruby192/lib/ruby/1.9.1/net/http.rb:644:in
连接来自C:/Ruby192/lib/ruby/1.9.1/net/http.rb:637的' :在do_start' from C:/Ruby192/lib/ruby/1.9.1/net/http.rb:626:in
从C:/Ruby192/lib/ruby/1.9.1/开始' net/http.rb:490:start' from heroes.rb:5:in
块中的' 从heroes.rb:3:upto' from heroes.rb:3:in
'