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
'