歡迎,我有一個問題,寶石mechanize不會連接到一個網站。寶石已安裝。 代碼:機械化不會連接到網站
require 'mechanize'
agent = Mechanize.new
main_page = agent.get 'https://imbd.com'
main_page.link_with(text: "Top 250").click
rows = list_page.root.css(".lister-list tr")
puts rows.size
,這是一個錯誤:
C:/Ruby/lib/ruby/2.2.0/net/http.rb:879:in `initialize': A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. - connect(2) for "imbd.com" port 80 (Errno::ETIMEDOUT)
from C:/Ruby/lib/ruby/2.2.0/net/http.rb:879:in `open'
from C:/Ruby/lib/ruby/2.2.0/net/http.rb:879:in `block in connect'
from C:/Ruby/lib/ruby/2.2.0/timeout.rb:73:in `timeout'
from C:/Ruby/lib/ruby/2.2.0/net/http.rb:878:in `connect'
from C:/Ruby/lib/ruby/2.2.0/net/http.rb:863:in `do_start'
from C:/Ruby/lib/ruby/2.2.0/net/http.rb:858:in `start'
from C:/Ruby/lib/ruby/gems/2.2.0/gems/net-http-persistent-2.9.4/lib/net/http/persistent.rb:700:in `start'
from C:/Ruby/lib/ruby/gems/2.2.0/gems/net-http-persistent-2.9.4/lib/net/http/persistent.rb:631:in `connection_for'
from C:/Ruby/lib/ruby/gems/2.2.0/gems/net-http-persistent-2.9.4/lib/net/http/persistent.rb:994:in `request'
from C:/Ruby/lib/ruby/gems/2.2.0/gems/mechanize-2.7.4/lib/mechanize/http/agent.rb:267:in `fetch'
from C:/Ruby/lib/ruby/gems/2.2.0/gems/mechanize-2.7.4/lib/mechanize.rb:464:in `get'
from C:/Ruby/Workspace/imbd.rb:4:in `<main>'
任何人有任何的想法有什麼不對?謝謝!
不知道。我只從他們的數據庫中提取10個標題。只是爲了教育的目的,而不是商業或垃圾郵件:)謝謝你的拼寫錯誤,現在我只是愚蠢的。在代碼的其他部分查找錯誤。 – Ioo