0
我想從本網站獲取我的駕駛執照號碼,issue_date和expiry_date(「https://sarathi.nic.in:8443/nrportal/sarathi/HomePage.jsp」)。當我嘗試獲取它時,出現錯誤Mechanize::ResponseCodeError: 500 => Net::HTTPInternalServerError for https://sarathi.nic.in:8443/nrportal/sarathi/DlDetRequest.jsp -- unhandled response
。如何解決HTTP 500錯誤,同時使用Ruby進行機械化報廢?
這是我寫的刮代碼:
require 'mechanize'
require 'logger'
require 'nokogiri'
require 'open-uri'
require 'openssl'
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
agent = Mechanize.new
agent.log = Logger.new "mech.log"
agent.user_agent_alias = 'Mac Safari 4'
Mechanize.new.get("https://sarathi.nic.in:8443/nrportal/sarathi/HomePage.jsp")
page=agent.get('https://sarathi.nic.in:8443/nrportal/sarathi/HomePage.jsp') # opening home page.
page = agent.page.links.find { |l| l.text == 'Status of Licence' }.click # click the link.
page.forms_with(:name=>"dlform").first.field_with(:name=>"dlform:DLNumber").value="TN38 20120001119" #user input to text field.
page.form_with(:name=>"dlform").field_with(:name=>"javax.faces.ViewState").value="SUBMIT" #submit button value assigning.
page.form(:name=>"dlform",:action=>"/nrportal/sarathi/DlDetRequest.jsp") #to specify the form i need.
agent.cookie_jar.clear!
gg=agent.submit page.forms.last #submitting my form
謝謝先生,但有一件事!我如何從輸出中提取我的DL號,發行日期和到期日期? –
你可以使用存儲「gg」的提交表單的響應來找到它。儘管您提供的號碼對我來說不起作用,並且從UI中嘗試失敗,所以只需檢查一次即可。 – Sam
噢,謝謝,我知道了,先生,再次感謝................................ –