Simple perl code is:
use WWW::Scripter;
...
my $w = WWW::Scripter->new('agent' => 'myAgent');
$w->use_plugin('JavaScript');
...
$w->get($url);
### WWW::Mechanize automatic cookies = good for now
$w->add_header(Referer => $url);
$url = $w->document->getElementsByTagName('a')->[0]->href;
$w->get($url);
...
### WWW::Mechanize automatic cookies = NOT good for now
### ! need to clear cookie jar here !
...
$w->add_header(Referer => $url);
$url = $w->document->getElementsByTagName('a')->[0]->href;
$w->get($url);
One of good feature of WWW::Mechanize
is automatic cookies, which is good at some point, but sometimes cookies need to be cleared. How?
The WWW::Mechanize
method cookie_jar
returns a HTTP::Cookies
object. The relevant method is indeed named clear
.