Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: $mech->content() returns empty

by kwaping (Priest)
on Oct 13, 2006 at 22:58 UTC ( [id://578228]=note: print w/replies, xml ) Need Help??


in reply to $mech->content() returns empty

$mech->submit_form(...) returns an HTTP::Response object (from the docs). It is that object that you need to call response on. Example:
# ... do stuff ... my $resp = $mech->submit_form(%params); print $resp->content if $resp->is_success;

---
It's all fine and dandy until someone has to look at the code.

Replies are listed 'Best First'.
Re^2: $mech->content() returns empty
by diotalevi (Canon) on Oct 13, 2006 at 23:32 UTC

    It also advances where the $mech object points to. $mech->content should be ok after the submit. I do agree, however, with your sentiment that checking the return value of ->submit_form is a good idea. The documentation mentions other things to check as well like ->success and ->status.

    ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

      I tried condensing the code a little bit to make it easier to figure out what goes wrong. The CONTENT is still empty but the URL shows that it did infact redirect to the proper page!

      In theory I could just get that URL, but it'd be a new instance of it when I need to know what the exact source code was once the form was submitted (to check for login errors).

      Any other suggestions?

      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, } ); die "Couldn't submit form" unless $mech->success; my $stuff = $mech->content; print $stuff; my $url = $mech->uri; print $url; }

        You can selectively disable the redirection. I suppose that if you need to examine something on the pre-redirect page that you'd use that feature.

        ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Re^2: $mech->content() returns empty
by Anonymous Monk on Oct 13, 2006 at 23:34 UTC
    I have used this syntax for quite a while where I can call $mech->content after submitting a form or following a link to get the next page's HTML source code.

    But just out of curiousity, I tried your suggestion but it, too, comes back completely empty.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://578228]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-04-25 23:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found