如何使用随机生成的用户名和密码输入名称的表单登录

时间:2021-05-01 19:21:31

I'm trying to login using a form which has no input names. The input names for the username and password form are randomly generated and change every time.

我正在尝试使用没有输入名称的表单登录。用户名和密码表单的输入名称是随机生成的,每次都会更改。

This is what I have so far:

这是我到目前为止:

require 'mechanize'

a = Mechanize.new

a.get('https://mijn.ing.nl/internetbankieren/SesamLoginServlet') do |page|

    login_form = page.forms.first

    login_form.username = '###'
    login_form.password = '###'

    dashboard_page = a.submit(login_form, login_form.buttons.first)

    # Check if the login was successfull
    puts check_1 = dashboard_page.title == 'Mijn ING Overzicht  - Mijn ING' ?  "CHECK 1 LOGIN SUCCESS" : "CHECK 1 LOGIN FAIL"

end

Here's the html code for the form:

这是表单的html代码:

<form action="/internetbankieren/SesamLoginServlet" autocomplete="off" class=
"" id="login" method="post" name="login">

  # Username (gebruikersnaam means username)
  <div class="form_element" id="gebruikersnaam">
    <label for="ah80VpuXfVPqNLULr">Gebruikersnaam</label>

    <div class="tooltip-icon"></div><input autofocus="autofocus" class=
    "firstfield" id="ah80VpuXfVPqNLULr" maxlength="20" name=
    "ah80VpuXfVPqNLULr" size="25" tabindex="1" type="text" value="">
  </div>

  # Password (wachtwoord means password)
  <div class="form_element" id="wachtwoord">
    <label for="ayp5rL2ao299ii2DG">Wachtwoord</label>

    <div class="tooltip-icon"></div><input class="" id="ayp5rL2ao299ii2DG"
    maxlength="20" name="ayp5rL2ao299ii2DG" size="25" tabindex="2" type=
    "password">

    <div class="notification hide-element">
      <div class="notification-icon notification-error"></div>

      <div class="notification-message"></div>
    </div>
  </div>

  <div class="form_element nolabel">
    <input id="aU1MyDLNfulG_xPJy" name="aU1MyDLNfulG_xPJy" tabindex="3" type=
    "checkbox"><label for="aU1MyDLNfulG_xPJy">Onthoud mijn
    gebruikersnaam</label>
  </div>

  <div class="form_element nolabel">
    <button class="submit" tabindex="4" title="Inloggen" type=
    "submit"><span>Inloggen</span></button>
  </div>

  <div class="form_element nolabel">
    <a class="link newWindow" href=
    "/internetbankieren/RequestAuthorisationLostCodesServlet" title=
    "">Inlogcodes vergeten?</a>
  </div><script language="javascript">
                          document.write("<INPUT TYPE='hidden' name='aJSJNaIvkvGj4Mzr2' value='" + urlEncode(add_deviceprint()) +"'>");
  </script><input name="aJSJNaIvkvGj4Mzr2" type="hidden" value=
  "version%3D2%26pm%5Ffpua%3Dmozilla%2F5%2E0%20%28macintosh%3B%20intel%20mac%20os%20x%2010%5F9%5F0%29%20applewebkit%2F537%2E36%20%28khtml%2C%20like%20gecko%29%20chrome%2F31%2E0%2E1650%2E63%20safari%2F537%2E36%7C5%2E0%20%28Macintosh%3B%20Intel%20Mac%20OS%20X%2010%5F9%5F0%29%20AppleWebKit%2F537%2E36%20%28KHTML%2C%20like%20Gecko%29%20Chrome%2F31%2E0%2E1650%2E63%20Safari%2F537%2E36%7CMacIntel%26pm%5Ffpsc%3D24%7C1920%7C1080%7C1058%26pm%5Ffpsw%3D%26pm%5Ffptz%3D1%26pm%5Ffpln%3Dlang%3Den%2DUS%7Csyslang%3D%7Cuserlang%3D%26pm%5Ffpjv%3D1%26pm%5Ffpco%3D1%26pm%5Ffpasw%3Dwidevinecdmadapter%7Cpepperflashplayer%7Cinternal%2Dremot#%2Dviewer%7Cppgooglenaclpluginchrome%7Cpdf%7Cadobeexmandetect%7Cdefault%20browser%7Cdymo%20npapi%20addin%7Cflash%20player%7Cflip4mac%20wmv%20plugin%7Cjavaappletplugin%7Cquicktime%20plugin%7Csharepointbrowserplugin%7Csilverlight%26pm%5Ffpan%3DNetscape%26pm%5Ffpacn%3DMozilla%26pm%5Ffpol%3Dtrue%26pm%5Ffposp%3D%26pm%5Ffpup%3D%26pm%5Ffpsaw%3D1920%26pm%5Ffpspd%3D24%26pm%5Ffpsbd%3D%26pm%5Ffpsdx%3D%26pm%5Ffpsdy%3D%26pm%5Ffpslx%3D%26pm%5Ffpsly%3D%26pm%5Ffpsfse%3D%26pm%5Ffpsui%3D">
  <input id="lptr" name="lptr" type="hidden" value=
  "{&quot;v4a&quot;:{&quot;r&quot;:&quot;0&quot;},&quot;v4b&quot;:{&quot;f&quot;:&quot;0&quot;},&quot;v7&quot;:{&quot;s&quot;:&quot;&quot;},&quot;v4&quot;:{&quot;j&quot;:&quot;&quot;},&quot;timestamp&quot;:&quot;2013-12-18 11:37:22&quot;,&quot;ki&quot;:&quot;1&quot;,&quot;v6&quot;:{&quot;u&quot;:&quot;&quot;,&quot;k&quot;:&quot;&quot;}}">
  <input id="lpts" name="lpts" type="hidden" value=
  "8dcca1458144f35323cea6cc160c6e72e92f323a33b33e9fcd1a71263361db1b">
</form>

I get the following error:

我收到以下错误:

/Users/username/.rvm/gems/ruby-2.0.0-p353@global/gems/mechanize-2.7.3/lib/mechanize/form.rb:217:in `method_missing': undefined method `username=' for #<Mechanize::Form:0x007f9e8c64c648> (NoMethodError)
    from ing.rb:9:in `block in <main>'
    from /Users/username/.rvm/gems/ruby-2.0.0-p353@global/gems/mechanize-2.7.3/lib/mechanize.rb:442:in `get'
    from ing.rb:5:in `<main>'

What's the best way to submit this kind of login form?

提交此类登录表单的最佳方式是什么?

2 个解决方案

#1


1  

It looks like you want to:

看起来你想:

a.follow_meta_refresh = true

#2


0  

Solved it by storing the randomly generated input names into variables and using them to identify the input fields.

通过将随机生成的输入名称存储到变量中并使用它们来标识输入字段来解决此问题。

Here's the code:

这是代码:

require 'mechanize'

# Instantiate a new Mechanize object
a = Mechanize.new

# Fetch URL with Mechanize
a.get('https://mijn.ing.nl/internetbankieren/SesamLoginServlet') do |page|
    a.follow_meta_refresh = true

    login_form = page.forms.first

    # Store the randomly generated input names into variables
    username_input_name = login_form.fields[0].name
    password_input_name = login_form.fields[1].name

    # Fill in the username and password form
    login_form.field_with(:name => username_input_name).value = 'username'
    login_form.field_with(:name => password_input_name).value = 'password'

    # Login
    dashboard_page = login_form.submit

    # Check if the login was successfull
    puts    "=================="
    puts check_1 = dashboard_page.title == 'Mijn ING Overzicht  - Mijn ING' ?  "CHECK 1 LOGIN SUCCESS" : "CHECK 1 LOGIN FAIL"
    puts    "=================="
end

#1


1  

It looks like you want to:

看起来你想:

a.follow_meta_refresh = true

#2


0  

Solved it by storing the randomly generated input names into variables and using them to identify the input fields.

通过将随机生成的输入名称存储到变量中并使用它们来标识输入字段来解决此问题。

Here's the code:

这是代码:

require 'mechanize'

# Instantiate a new Mechanize object
a = Mechanize.new

# Fetch URL with Mechanize
a.get('https://mijn.ing.nl/internetbankieren/SesamLoginServlet') do |page|
    a.follow_meta_refresh = true

    login_form = page.forms.first

    # Store the randomly generated input names into variables
    username_input_name = login_form.fields[0].name
    password_input_name = login_form.fields[1].name

    # Fill in the username and password form
    login_form.field_with(:name => username_input_name).value = 'username'
    login_form.field_with(:name => password_input_name).value = 'password'

    # Login
    dashboard_page = login_form.submit

    # Check if the login was successfull
    puts    "=================="
    puts check_1 = dashboard_page.title == 'Mijn ING Overzicht  - Mijn ING' ?  "CHECK 1 LOGIN SUCCESS" : "CHECK 1 LOGIN FAIL"
    puts    "=================="
end