P
Phil Henley
I'm writing a script to login to my bank. Here's how the login
procedure works through a web browser:
1. enter and submit your username on the bank home page
2. on a new page: answer a "Shield ID" question (a personalized
question)
3. on a new page: enter your password
4. on a new page: you now have access to your account info
Using Firefox and the Live HTTP Headers add-on, I see that javascript
(or something??) is filling out various forms for me at each step which
takes me to the next page. Only one of these forms is visible to the
user in the browser at each step (login at step 1, and shield id at step
2), javascript seems to be filling out the rest of the forms for the
user.
In my script, I'm using Mechanize to manually fill out and submit all
these forms.
This works fine until I get to Step 3 where you enter your password.
When I view the forms on this page with Mechanize only two forms show
up. The password form (as well as a few others) don't show up.
If I go through the process with FireFox and the add-on mentioned above,
I see that the form holding my password is called PSWD, but if I try to
access that form directly from my script it can not find the form.
Any ideas how I can access this form from my script?
Here's a quick example of the code I'm using:
agent = Mechanize.new
page = agent.get "http://www.usbank.com/en/PersonalHome.cfm"
form = page.form('logon2')
form.requestCmdId = "VALIDATEID"
form.reqcrda = "my_username"
form.reqcrdb = ""
form.doubleclick = "1"
form.NONCE = "NoNonce"
form.MACHINEATTR =
"colorDepth%3D24%7Cwidth%3D2048%7Cheight%3D1152%7CavailWidth%3D2048%7CavailHeight%3D1122%7Cplatform%3DWin32%7CjavaEnabled%3DNo%7CuserAgent%3DMozilla%2F5.0+%28Windows%3B+U%3B+Windows+NT+6.1%3B+en-US%3B+rv%3A1.9"
form.bankLogin = "internetBanking"
form.USERID = "my_username"
page = agent.submit form
#Get the Shield ID question
question = page.body.match(%r|<td class=f3 colspan=3
valign="middle">.*?</td>|).to_s.sub('<td class=f3 colspan=3
valign="middle">', '').sub("</td>", "")
result = case question
when "question 1" then "answer1"
when "question 2" then "answer2"
else "failed"
end
if result == "failed"
puts "\nFailed to answer the ID Shield question."
puts question
sleep 3
exit
end
form = page.form('challenge')
# ID Shield answer
form.ANSWER = result
form.CHALLENGEANSWER = result
page = agent.submit form
#We are now on the password page
form = page.form('password')
form.PSWD = "my_password"
- here is where I get an error "undefined method 'PSWD='
procedure works through a web browser:
1. enter and submit your username on the bank home page
2. on a new page: answer a "Shield ID" question (a personalized
question)
3. on a new page: enter your password
4. on a new page: you now have access to your account info
Using Firefox and the Live HTTP Headers add-on, I see that javascript
(or something??) is filling out various forms for me at each step which
takes me to the next page. Only one of these forms is visible to the
user in the browser at each step (login at step 1, and shield id at step
2), javascript seems to be filling out the rest of the forms for the
user.
In my script, I'm using Mechanize to manually fill out and submit all
these forms.
This works fine until I get to Step 3 where you enter your password.
When I view the forms on this page with Mechanize only two forms show
up. The password form (as well as a few others) don't show up.
If I go through the process with FireFox and the add-on mentioned above,
I see that the form holding my password is called PSWD, but if I try to
access that form directly from my script it can not find the form.
Any ideas how I can access this form from my script?
Here's a quick example of the code I'm using:
agent = Mechanize.new
page = agent.get "http://www.usbank.com/en/PersonalHome.cfm"
form = page.form('logon2')
form.requestCmdId = "VALIDATEID"
form.reqcrda = "my_username"
form.reqcrdb = ""
form.doubleclick = "1"
form.NONCE = "NoNonce"
form.MACHINEATTR =
"colorDepth%3D24%7Cwidth%3D2048%7Cheight%3D1152%7CavailWidth%3D2048%7CavailHeight%3D1122%7Cplatform%3DWin32%7CjavaEnabled%3DNo%7CuserAgent%3DMozilla%2F5.0+%28Windows%3B+U%3B+Windows+NT+6.1%3B+en-US%3B+rv%3A1.9"
form.bankLogin = "internetBanking"
form.USERID = "my_username"
page = agent.submit form
#Get the Shield ID question
question = page.body.match(%r|<td class=f3 colspan=3
valign="middle">.*?</td>|).to_s.sub('<td class=f3 colspan=3
valign="middle">', '').sub("</td>", "")
result = case question
when "question 1" then "answer1"
when "question 2" then "answer2"
else "failed"
end
if result == "failed"
puts "\nFailed to answer the ID Shield question."
puts question
sleep 3
exit
end
form = page.form('challenge')
# ID Shield answer
form.ANSWER = result
form.CHALLENGEANSWER = result
page = agent.submit form
#We are now on the password page
form = page.form('password')
form.PSWD = "my_password"
- here is where I get an error "undefined method 'PSWD='