Tips to add cookies using Perl www::mechanize

June 14, 2008

In the Perl module www::Mechanize, it is easy to disable the cookie by using:

my $mech = WWW::Mechanize->new();

When you want to initialize the new Cookie, using
will not always work.

However, you can use the following couple of lines to add the Cookie:
$cj=HTTP::Cookies->new(file => “cookie.jar”,autosave=>1,ignore_discard=>1);
$mech = WWW::Mechanize->new(cookie_jar => $cj);

The cookie is saved under the file “cookie.jar” in the current running dir.