johnblack has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

I am trying to write a script that logs into chase.com and grabs account information for two or three accounts automatically. I originally tried WWW::Mechanize but I could not get all the way in because of all the js, cookies etc. that were being thrown back at me.

I was pointed to Mechanize::Firefox which seemed perfect because Firefox already knows how to do all that stuff. I post my code below which I can see is loading up the site and submits the form does not finish. I just end up on a blank page called: https://mfasa.chase.com/auth/login.html. I want the script to go to the home page, fill in the userid and password and submit it and then let firefox do its thing as if I did those things from the browser directly. Any suggestions on what I may be missing are appreciated. Oh, all status' returned are 200.

#!/usr/bin/perl use strict; use warnings; use WWW::Mechanize::Firefox; my $mech = WWW::Mechanize::Firefox->new(); my $url = 'https://www.chase.com/'; sub print_status() { my $status =$mech->status(); print "status = $status\n"; } $mech->get($url, activate => 1, autoclose => 0, js_JSON => 'native'); # Tried this - did not help. print_status(); my $username = 'XXXXXXXX'; my $password = 'XXXXXXXX'; $mech->form_name ('logonform') ; $mech->field (usr_name => $username); $mech->field (usr_password => $password); print_status(); $mech->submit_form(); print_status();

Replies are listed 'Best First'.
Re: Need help logging into my bank with WWW::Mechanize::Firefox
by PerlSufi (Friar) on Dec 08, 2014 at 22:39 UTC
    Keeping in mind that doing any of this may not be accepted in their Terms of Use, maybe you can try something like:
    $mech->submit_form( with_fields => { usr_name => 'me', usr_password => 'secret', } );

    ..While deleting the '$mech->form_name' ..line
    Also, I'm really unsure why you are using a separate subroutine to get the status. You could just call $mech->status instead? If I was to put any of your script(when it works) into a sub, it would be the login process.
    Are you watching to make sure that the script is actually filling out the form?
    UPDATE: Are you sure the name of that form is correct on that route? When I inspect with FireBug, I see the form name as 'homeLogonForm' ..not 'logonform'. Definitely make sure you are specifying the right one- If my above suggestion doesn't work.

      Thanks for your reply. I tried your with_fields suggestion and got this message:

      2 elements found for form with fields usr_password usr_name at mon2.pl line 32.

      By trial and error I found that those are forms number 3 and 4 but when I try both form numbers I get the same result as before when I was going with the form name of logonform.

      >>Are you watching to make sure that the script is actually filling out the form?

      Yes, I can see that it is.

      >>UPDATE: Are you sure the name of that form is correct on that route? When I inspect with FireBug, I see the form name as 'homeLogonForm' ..not 'logonform'.

      That explains why calling "with_fields" finds 2 forms that match the fields. I found logonform by code inspection but I switched to homeLogonForm and am getting the same result. If I was using an incorrect name or incorrect fields for the name, Mechanize::Firefox reports an error.

        I feel like I'm close. If I exit my script before the call to submit_form(), it has the page called up and has filled in the userid and pwd. If I then manually click the green button that says Log In To Accounts, I get in.

        But I can't figure out how to do that from within Mechanize::Firefox. If I go by button number, I am told there is only one button on the page. If I click that one, I find out that it is the search button. So if that log in button is not a "button", what is it and how can I click it? Thanks.

Re: Need help logging into my bank with WWW::Mechanize::Firefox
by Anonymous Monk on Dec 08, 2014 at 21:57 UTC

    One approach is to trace the web traffic with Wireshark and comparing a normal, manual login with the automated one. Perhaps the differences could reveal what is going wrong.

Re: Need help logging into my bank with WWW::Mechanize::Firefox
by trippledubs (Deacon) on Dec 09, 2014 at 18:48 UTC
    Maybe the monks are helping the OP check the latest pw dump against Chase.com