WWW :: Mechanization and Cookies

I am using WWW :: Mechanize :: Shell for testing. Since I was unable to enter the website, I want to clear it, I thought that I would use a browser cookie (chrome or firefox) for this particular site with the cookie command WWW :: Mechanize :: Shell.

The question is that cookies are usually stored in one file, which is not very good, how to get cookies only for this particular site?

thanks,

+4
source share
2 answers

Why cookies are not saved in the file?

Since WWW :: Mechanize is built on top of LWP :: UserAgent , you process cookies just like in LWP :: UserAgent . You can make a cookie or hash memory in memory.

If you do not want to save cookies in a file, use an empty hash link when creating the mech object:

use WWW::Mechanize; my $mech = WWW::Mechanize->new( cookie_jar => {} ); 

If you want to use the new file, create a new HTTP :: Cookies object:

  use WWW::Mechanize; my $mech = WWW::Mechanize->new( cookie_jar => HTTP::Cookies->new( file => "$ENV{HOME}/.cookies.txt" ) ); 

If you want to load a specific cookie for the browser, use the correct module for it:

  use WWW::Mechanize; my $mech = WWW::Mechanize->new( cookie_jar => HTTP::Cookies::Netscape->new( file => $filename ) ); 

If you don't want to use cookies at all, use undef explicitly:

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

All this is in the docs.

+10
source

HTTP::Cookies::Netscape , HTTP::Cookies::Microsoft download your existing browser cookies.

+5
source

All Articles