Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Weird problem that I can't solve after many, many attempts. I have a script that uses WWW::Mech to login to my message board.
It loads the LOGIN page fine (tested this by dumping $mech->content after I $mech->get( $forum_login ); and seeing the HTML source code.
The script then puts in the data to the forum fields (does NOT error out saying it cannot find such form fields) which appears as though it's working just fine.
Then I run a test on $mech->content to check for a FAILURE string (ie: Username and password incorrect) that would appear on a failed attempt to login. Now this FAILS because the following page comes back empty (after the login data is submitted).
Can anyone help me figure out why I'm losing my mech content after the login form is submitted?$forum_login = ""; $forum_type = "number"; # either NUMBER or NAME depending if specific +form will be found by name or number $forum_call = "1"; #form number or name for login $forum_user ="username"; #NAME of the forum field for username $forum_pass = "passwrd"; #NAME of the forum field for username $username = ""; # username to signing $password = ""; # password to signin $forum_fail = "incorrect"; # text to find if login failed # # above empty variables are emptied for obvious reasons # in this sample source code use LWP::Simple; use WWW::Mechanize; my $mech = WWW::Mechanize->new(); $mech->cookie_jar(HTTP::Cookies->new); $mech->get( $forum_login ); if ($forum_type eq "number") { $mech->submit_form( form_number => $forum_call, fields => { $forum_user => $username, $forum_pass => $password, } ); print "Good!"; } else { $mech->submit_form( form_name => $forum_call, fields => { $forum_user => $username, $forum_pass => $password, } ); print "Good!"; } print $mech->content; # comes back empty exit; . . ####################### # Was sign in successful? ####################### if ($mech->content =~ m/$forum_fail/i || $mech->content eq "") { my $time = localtime(); open(LOG, ">> error.txt") or die "Error: $!"; print LOG $time; print LOG $mech->response; print LOG "\n"; close(LOG) or die "Error: $!"; print $mech->content; print "ERROR:" . $mech->response; } else { print "LOGGED IN!"; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: $mech->content() returns empty
by sulfericacid (Deacon) on Oct 14, 2006 at 02:51 UTC | |
by Anonymous Monk on Oct 14, 2006 at 03:02 UTC | |
Re: $mech->content() returns empty
by kwaping (Priest) on Oct 13, 2006 at 22:58 UTC | |
by diotalevi (Canon) on Oct 13, 2006 at 23:32 UTC | |
by Anonymous Monk on Oct 13, 2006 at 23:50 UTC | |
by diotalevi (Canon) on Oct 13, 2006 at 23:55 UTC | |
by Anonymous Monk on Oct 14, 2006 at 00:21 UTC | |
| |
by Anonymous Monk on Oct 13, 2006 at 23:34 UTC |
Back to
Seekers of Perl Wisdom