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).

$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!"; }
Can anyone help me figure out why I'm losing my mech content after the login form is submitted?

In reply to $mech->content() returns empty by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.