このウェブサイト(「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
が出ます。RubyでMechanizeを使用してWebをスクラップするときにHTTP500エラーを解決するにはどうすればよいですか?
これは私が掻き取る書いたコードです:
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
ありがとうございますが、1つのこと! DL no、Issue date、expiry dateを出力からどのように抽出できますか? –
"gg"に保存された送信フォームの応答を使用して見つけることができます。あなたが提供した番号は私のためには機能しませんでしたが、無効なUIとして試してみたので、一度確認してください。 – Sam
ああ、ありがとう、私はそれを受け取りました、もう一度感謝................................ –