Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

javascript login

by robertw (Sexton)
on Aug 02, 2012 at 15:28 UTC ( #985054=perlquestion: print w/ replies, xml ) Need Help??
robertw has asked for the wisdom of the Perl Monks concerning the following question:

wise perlmonks, <\p>

I have been willing to use www::Mechanize to login to the following site https://login.binck.nl/klanten/Login.aspx?ReturnUrl=%2fklanten%2fdefault.aspx but i believe it uses javascript, what would be the best module to use for javascript web pages? I am also writing a program that trades shares,everything is going fine only i have no idea how to process the orders with the web: making the program wait for confirmation of the order, logging in broker, making the program do what i would do if i bought via web broker. What would books would help me in my cause?

Thank you very much in advance

Comment on javascript login
Re: javascript login
by marto (Chancellor) on Aug 02, 2012 at 15:40 UTC

    "I am also writing a program that trades shares,everything is going fine only i have no idea how to process the orders with the web: making the program wait for confirmation of the order, logging in broker, making the program do what i would do if i bought via web broker. What would books would help me in my cause?"

    I don't understand Dutch but you should check to ensure that this does not violate the terms and conditions of the website. I notice they provide other products/services for trading. Perhaps they have an API which you can use which would actually solve some of these problems for you.

Re: javascript login
by bulk88 (Priest) on Aug 02, 2012 at 15:41 UTC
    Turn off images in the browser, load the login page, turn on Wireshark to sniff the Ethernet interface, type in username/pass, click login, let destination page load, stop wireshark capture. Use the capture data to replicate in LWP what the JS did (POST or GET or whatever). Use wireshark to see what LWP is doing, and how good your LWP code is compared to a real browser.

      And if you feel uncomfortable with Ethereal/Wireshark, you can use Mozilla extensions such as LiveHTTPHeaders or Firebug. Or just figure out what the JavaScript is doing manually. (Given how common these questions here are, someone really ought to write a "How to deal with JavaScript" document.)

Re: javascript login
by zentara (Archbishop) on Aug 02, 2012 at 17:11 UTC
Re: javascript login
by aitap (Deacon) on Aug 03, 2012 at 14:36 UTC

    You can use WWW::Mechanize::Firefox (as its engine do run javascript; your program will depend on the browser) or read javascript manually and write some Perl logic which does the same by parsing values from the page source.

    You can also try WWW::Scripter (and WWW::Scripter::Plugin::JavaScript) or WWW::Mechanize::Plugin::Ajax.

    Myself, I prefer reading JS manually and writing same logic in Perl. It leaves my scripts simple whan I'm working with small and simple sites.

    Sorry if my advice was wrong.
      Thank you all so much for the help, I have an applescript that logged in on the site, but I have no idea how to do that in perl
      do shell script "open -a safari 'https://login.binck.nl/klanten/Login. +aspx?ReturnUrl=%2fklanten%2fdefault.aspx'" tell application "Safari" activate tell document 1 repeat until ((do JavaScript "location.host") is "login.binck. +nl") delay 1 end repeat do JavaScript "document.getElementById('ctl00_Content_Gebruike +rsnaam').value='username';document.ge tElementById('ctl00_Content_Wac +htwoord').value='password';window.open(document.g etElementById('ctl0 +0_Content_LoginButton').href, '_self', 'true');" end tell end tell

        After reading WWW::Mechanize::Cookbook, I can suggest the following:

        1. Install WWW::Mechanize::Firefox
        2. Install the MozRepl plugin in your Firefox
        3. use WWW::Mechanize::Firefox; my $mech = WWW::Mechanize::Firefox->new( launch => '/path/to/firefox', ); $mech->get('https://login.binck.nl/klanten/Login.aspx?ReturnUrl=%2fkla +nten%2fdefault.aspx'); $mech->eval(q{document.getElementById('ctl00_Content_Gebruikersnaam'). +value='username';document.getElementById('ctl00_Content_Wachtwoord'). +value='password'; window.open(document.getElementById('ctl00_Content_LoginButton').href, + '_self', 'true');});

        This is just an untested rewrite of your AppleScript in Perl. It's possible that even Firefox is not needed (and only WWW::Mechanize is required), but I was not able to find the form ID on the login page because the page doesn't work for me.

        Sorry if my advice was wrong.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://985054]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (9)
As of 2014-07-13 15:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (250 votes), past polls