1
 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!"

スクリプトを実行すると、次のエラーが発生します。

C:/Ruby192/lib/ruby/1.9.1/net/http.rb:644:in initialize': getaddrinfo: No such host is known. (SocketError) from C:/Ruby192/lib/ruby/1.9.1/net/http.rb:644:inopen'from C:/Ruby192/lib/ruby/1.9.1/net/http.rb:644:in block in connect' from C:/Ruby192/lib/ruby/1.9.1/timeout.rb:44:intimeout' from C:/Ruby192/lib/ruby/1.9.1/timeout.rb:89:in timeout' from C:/Ruby192/lib/ruby/1.9.1/net/http.rb:644:inconnect'from C:/Ruby192/lib/ruby/1.9.1/net/http.rb:637:in do_start' from C:/Ruby192/lib/ruby/1.9.1/net/http.rb:626:instart' from C: /Ruby192/lib/ruby/1.9.1/net/http.rb:490:in start' from heroes.rb:5:inblock in'from heroes.rb:3:in upto' from heroes.rb:3:in'

4

1 に答える 1