Special_K has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to use WWW::Mechanize to automate navigation of a webpage that requires me to click on at least one button that is tied to javascript code. I know that WWW::Mechanize does not support javascript but am trying to avoid using WWW::Mechanize::Firefox because I don't want to deal with the GUI.
Given that, I am trying to decipher the data that is transmitted when I navigate through the website using a browser to see if I can just manually do what the javascript is doing within my perl code.
When I click the button manually, here is the POST data:
cbd_ria:true ANSWER:******* LoginForm:ANSWER:******* LoginForm:DEVICE:true ANTI_CSRF_TOKEN:9ec2f31c-4008-4bce-b759-3b3aceda6f42 LoginForm:LoginForm
Here is the response header:
Content-language:en-US Content-length:0 Date:Fri, 04 Jul 2014 04:12:25 GMT Location:https://****************************** P3p:CP='NOI CURa ADMa DEVa TAIa OUR BUS IND UNI COM NAV INT' Set-cookie:PMData=PMV6GDrDYODTPUcMqubLWUJOi%2BhcTJGSUaC%2B%2Fk0FN2ITW8 +Isa1Awx90hD%2B3wCtpjInRT5Gw%2Bye28N9Tr6uhoe8T9R30g%3D%3D;path=/;HttpO +nly; Expires=Sat, 04 Jul 2015 04:12:24 GMT; Domain=**********.com; Se +cure X-frame-options:SAMEORIGIN
When I manually fill out the boxes corresponding to LoginForm:ANSWER and LoginForm:DEVICE and then click the continue button, the website authenticates my responses and then takes me to the location specified in the "Location:" field of the response header, which is where I intend to go.
How would I replicate what the javascript is doing within perl? Do I just fill out all the fields in the POST data above, and then GET the Location: URL?
Filling out the LoginForm:ANSWER and LoginForm:DEVICE fields is easy enough, but what about the ANTI_CSRF_TOKEN? I have no idea how to generate it. Is it even required?
Also I did some searching and stumbled on a few perl javascript engines such as JavaScript::SpiderMonkey, WWW-Scripter-Plugin-JavaScript, and WWW-Mechanize-PhantomJS. All of these have an eval() function. The button I am trying to press has the following code tied to it:
<input type="button" value="Continue" tabindex="1" onkeypress="fd.butt +on._keyPress(event, 'LoginForm:continue')" initialtabindex="1" class= +"btn" id="LoginForm:continueInput">
In this case, the button appears to take the following action:
fd.button._keyPress(event, 'LoginForm:continue')
If I use one of the javascript modules, is it literally as simple as calling eval on the function bound to the button once I have set the appropriate variables (I assume the JS function will handle the ANTI_CSRF_TOKEN?)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: WWW::Mechanize and buttons tied to javascript
by Anonymous Monk on Jul 04, 2014 at 06:51 UTC | |
by Special_K (Pilgrim) on Jul 04, 2014 at 17:29 UTC | |
by Anonymous Monk on Jul 05, 2014 at 03:14 UTC |