I wanted to build an awesome place for people to discuss module specific issues, but I don't have any more time for this, and there are much better places to discuss Perl-related issues. I'd recommend asking your question on Stack Overflow or on Perl Monks.
If you are looking for a Perl tutorial or Perl-related news, I hope these links will serve you well.
Posted on 2009-02-21 19:33:38-08 by wax
login problem
Hello, I'm having a problem with WWW::Mechanize that I hope that someone more knowledgeable than myself can help me with. I want to automate logging on to the investopedia stock simulator web site. http://simulator.investopedia.com/authorization/login.aspx I can't seem to automate this successfully. My perl script is below:
#!/usr/bin/env perl use strict; use Net::HTTP; use LWP::UserAgent; use WWW::Mechanize; my $site="http://simulator.investopedia.com"; my $url=$site . "/authorization/login.aspx"; my $ua = WWW::Mechanize->new(autocheck => 1); $ua->cookie_jar({}); $ua->get($url); my $username = "XXX"; my $password = "XXX"; #$ua->credentials( $url, $username, $password ); # the login page: # my $page = $ua->content(); print $page; print "DONE"; print "\n"; $ua->submit_form( form_number => 0, fields => { 'ctl00$MainPlaceHolder$usernameText' => $username, 'ctl00$MainPlaceHolder$passwordText' => $password, }, ); print $ua->content();
but the resulting page I print does not look like what I get when I manually click the submit button at all. It returns me to the login page again. I must be doing something incorrectly. Can someone with more knowledge shed some light on my mistakes ... *ANY* hints/suggestions/directions would be very appreciated since I've run out of ideas of things to try at this point. Thanks very much PS. I tried the "credentials" call with no luck either.
Direct Responses: 10154 | Write a response
Posted on 2009-03-11 21:44:40-07 by runes in response to 10042
Re: login problem

You should click the button, rather than submitting the form, so I suggest:
$ua->field('ctl00$MainPlaceHolder$usernameText' => $username);
$ua->field('ctl00$MainPlaceHolder$passwordText' => $password);
$ua->click;

WWW::Mechanize handles cookies just fine by default, so there is no need to do $ua->cookie_jar({});

Direct Responses: Write a response