Javascript 如何在perl中使用WWW::Scripter模块显式清除Cookie?
简单的perl代码是:Javascript 如何在perl中使用WWW::Scripter模块显式清除Cookie?,javascript,perl,cookies,lwp,Javascript,Perl,Cookies,Lwp,简单的perl代码是: use WWW::Scripter; ... my $w = WWW::Scripter->new('agent' => 'myAgent'); $w->use_plugin('JavaScript'); ... $w->get($url); ### WWW::Mec
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);
WWW::Mechanize
的一个好特性是自动cookies,这在某些方面是好的,但有时需要清除cookies。如何设置?,您不能重置cookie jar属性吗
e、 g
WWW::Mechanize
方法cookie\u jar
返回一个HTTP::Cookies
对象。相关方法确实已命名。我不确定,但您的代码是否会禁用Cookie?我想的更多的是$w->cookie\u jar->clear
或$w->cookie\u jar()->clear
?如果你看源代码,当参数设置一个新的cookie\u jar时,它看起来像一个空散列。所以它应该是$w->cookie\u jar->->clear
或$w->cookie\u jar()->()->clear
,那么两者都是有效的,当函数/方法不带参数时,可以省略空括号。选择一种方法并始终如一地应用它。如果不确定,请查阅样式指南、其他人的代码和书籍,例如。
$w->cookie_jar({});