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

Hello, Monks!

This is my first foray into the perl world, so pre-apologies for anything terribly noobish.
Here's my problem: I'm trying to make a script that logs in and checks the balance in my bank for me. WWW-Mechanize works extremely well for most of it, and I got all the regexs to work on a local copy of the data, but when I tried it live, it all fails.

After senseless frustration, I realized the hang-up: after mechanize fills in the username and password on the form, it clicks submit and returns the source of the page located after that link. The problem is that, after you click "sign on," wells fargo redirects you through a number of pages on its way to the main page ("authorizing","retreiving info," etc). Does anyone know how to make my $mech follow complex redirects?

Thank you!!
  • Comment on WWW::Mechanize - Wait until redirected page returned

Replies are listed 'Best First'.
Re: WWW::Mechanize - Wait until redirected page returned
by diotalevi (Canon) on Dec 09, 2004 at 18:26 UTC
    WWW::Mechanize will follow redirects but won't execute JavaScript. If your redirects are occuring as a result of JavaScript execution, you'll need to write code to read the JavaScript, find the next URL, and do a ->get() on the new URL to get it to skip past that stuff.
Re: WWW::Mechanize - Wait until redirected page returned
by Joost (Canon) on Dec 09, 2004 at 18:22 UTC
    I think WWW::Mechanize automatically follows HTTP redirects, if not, you can subclass WWW::Mechanize to override the redirect_ok() subroutine. Also, since WWW::Mechanize is itself a subclass of LWP::UserAgent, it might help to set max_redirect() to some higher value, and/or set request_redirectable(). see the LWP::UserAgent documentation.

    package My::Mech; # My::Mech is a subclass of WWW::Mechanize use base qw(WWW::Mechanize); # always allow redirects, irrespective of # request_redirectable sub redirect_ok { return 1; }

    However, your bank's website might use META tags or javascript for "redirects". If so, you have to do the redirection yourself. Depending on the exact format of the page, you could get away with a simple regex, or maybe you need an HTML::Parser to find the redirection URL.