ruby - Mechanize script keeps stopping with `fetch': 503 => Net::HTTPServiceUnavailable -
i trying run local ruby script using mechanize logs me onto website , goes through 1500 of webpages , parses information each of them. parsing works, length of time; script runs 45 seconds or so, , stops , reports:
/users/myname/.rvm/gems/ruby-1.9.3-p374/gems/mechanize-2.7.1/lib/mechanize/http/agent.rb:306:in `fetch': 503 => net::httpserviceunavailable http://example.com/page;53 -- unhandled response (mechanize::responsecodeerror)
i can't tell sure, feel due connection timeout. tried resolving in script long timeout (this script take 15 minutes run), still doesn't change anything. let me know if have ideas.
this script:
require 'mechanize' require 'open-uri' require 'rubygems' agent = mechanize.new agent.open_timeout = 1000 agent.read_timeout = 1000 agent.max_history = 1 page = agent.get('examplesite.com') myform = page.form_with(:action => '/maint') myuserid_field = myform.field_with(:id => "username") myuserid_field.value = 'myusername' mypass_field = myform.field_with(:id => "password") mypass_field.value = 'mypassword' page = agent.submit(myform, myform.buttons.first) urlarray = [giant array of webpages here] urlarray.each |term| page = agent.get('' + term + '') page.encoding = 'windows-1252' puts agent.page.parser.xpath("//tr[4]/td[2]/textarea/text()").text + 'newlinehere' end
try calling sleep(1)
in each loop. it's target server overwhelmed requests without pause.
Comments
Post a Comment