我正在使用 Capybara(Selenium 驱动程序)访问网站上的某些页面。我只需单击数组中的每个项目,然后单击后退按钮。它运行良好,但每次经过一些迭代后它都会中断。这是代码:
all(:xpath, '//table[@class="griglia_bordata"]//tr[td]/td/a[1]').each do |a|
a_js_functions << a[:href]
end
a_js_functions.each do |js_for_model|
puts js_for_model
page.execute_script js_for_model
find(:xpath, "//a[text()='Check availability']").click
puts find(".testo_grande_blu_B").text
puts "--------------------------------------------"
find(:xpath, "//a[text()='Back']").click
end
我有输出:
javascript:selectModel('130254') 样式:RB2132 --------------------------------------- ----- javascript:selectModel('309257') 样式:RB2140 ---------------------------------- ---------- javascript:selectModel('68238') 样式:RB3016 ----------------------------- --------------- javascript:selectModel('68248') 样式:RB3025 ------------------------ -------------------- javascript:selectModel('68293') 样式:RB3026 -------------------- ------------------------- javascript:selectModel('68320') 样式:RB3044 -------------- ------------------------------ javascript:selectModel('68460') /usr/lib/ruby/1.9.1/net /protocol.rb:146:in
rescue in rbuf_fill': Timeout::Error (Timeout::Error) from /usr/lib/ruby/1.9.1/net/protocol.rb:140:in
rbuf_fill' 来自 /usr/lib/ruby/1.9.1/net/protocol.rb:122:inreaduntil' from /usr/lib/ruby/1.9.1/net/protocol.rb:132:in
readline' 来自 /usr/lib/ruby/1.9.1/net/http.rb :2562:在read_status_line' from /usr/lib/ruby/1.9.1/net/http.rb:2551:in
从 /usr/lib/ruby/1.9.1/net/http.rb:1319:in 中读取新的'从 /usr/lib/ruby/1.9.1/net/http.rb:1316:in 中block in transport_request' from /usr/lib/ruby/1.9.1/net/http.rb:1316:in
捕获'transport_request' from /usr/lib/ruby/1.9.1/net/http.rb:1293:in
来自/的请求' usr/lib/ruby/1.9.1/net/http.rb:1286:inblock in request' from /usr/lib/ruby/1.9.1/net/http.rb:745:in
start' from /usr/lib/ruby/1.9.1/net/http.rb:1284:inrequest' from /var/lib/gems/1.9.1/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/remote/http/default.rb:82:in
response_for' from /var/lib/ gems/1.9.1/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/remote/http/default.rb:38:inrequest' from /var/lib/gems/1.9.1/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/remote/http/common.rb:40:in
call'来自/var/lib/gems/1.9.1/gems/selenium -webdriver-2.25.0/lib/selenium/webdriver/remote/bridge.rb:598:inraw_execute' from /var/lib/gems/1.9.1/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/remote/bridge.rb:576:in
execute' 来自 /var/lib/gems/1.9.1/gems/selenium-webdriver-2.25.0/lib/selenium/ webdriver/remote/bridge.rb:554:infind_elements_by' from /var/lib/gems/1.9.1/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/common/search_context.rb:62:in
find_elements' from /var/lib/gems/1.9.1/gems/capybara-1.1.2/lib/capybara/selenium/driver.rb:52:infind' from /var/lib/gems/1.9.1/gems/capybara-1.1.2/lib/capybara/node/finders.rb:158:in
find_in_base' 来自 /var/lib/gems/1.9.1/gems/capybara-1.1.2/lib/capybara/node/finders.rb:137:inblock in first' from /var/lib/gems/1.9.1/gems/capybara-1.1.2/lib/capybara/node/finders.rb:136:in
each' 来自 /var/lib/gems/1.9.1/gems /capybara-1.1.2/lib/capybara/node/finders.rb:136:infirst' from /var/lib/gems/1.9.1/gems/capybara-1.1.2/lib/capybara/node/finders.rb:27:in
block in find' from /var/lib/gems/1.9.1/gems/capybara-1.1.2/lib/capybara/node/ base.rb:46:inwait_until' from /var/lib/gems/1.9.1/gems/capybara-1.1.2/lib/capybara/node/finders.rb:27:in
find' from (eval):2:infind' from /var/lib/gems/1.9.1/gems/capybara-1.1.2/lib/capybara/dsl.rb:161:in
find' from /home/biske/workspace/ScrapingGlasses/lib/luxottica.rb:39:inblock in scrape' from /home/biske/workspace/ScrapingGlasses/lib/luxottica.rb:36:in
each' from /home/biske/workspace/ScrapingGlasses/ lib/luxottica.rb:36:inscrape' from /home/biske/workspace/ScrapingGlasses/lib/luxottica.rb:12:in
go' 来自 /home/biske/workspace/ScrapingGlasses/lib/luxottica.rb:48:in `'