WWW::Mechanize Perl login only works after relaunch

Posted by Klaus on Stack Overflow See other posts from Stack Overflow or by Klaus
Published on 2010-03-27T11:08:56Z Indexed on 2010/03/27 11:13 UTC
Read the original article Hit count: 493

Filed under:
|
|
|

Hello,

I'm trying to login automatically in a website using Perl WWW::Mechanize.

What I do is:

$bot = WWW::Mechanize->new();
$bot->cookie_jar(
        HTTP::Cookies->new(
            file           => "cookies.txt",
            autosave       => 1,
            ignore_discard => 1,
        )
);

$response = $bot->get( 'http://blah.foo/login' );

$bot->form_number(1);

$bot->field( usern => 'user' );
$bot->field( pass => 'pass' );
$response =$bot->click();

print $response->content();

$response = $bot->get( 'http://blah.foo' );

print $response->content();

The login works, but when I load the page it tells me that I am not connected.

You see that I store cookies in a file. Now if I relaunch the script without the login part, it says that I am connected...

Does anyone understand this strange behaviour ?

© Stack Overflow or respective owner

Related posts about perl

Related posts about mechanize