如何在perl中使用WWW :: Scripter模块明确清除cookie?

时间:2012-03-05 16:32:56

标签: javascript perl cookies lwp

简单的 perl 代码是:

      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的一个很好的功能是自动Cookie ,这在某些方面很好,但有时需要清除Cookie。怎么样?

2 个答案:

答案 0 :(得分:2)

WWW::Mechanize方法cookie_jar返回HTTP::Cookies个对象。相关方法的确名为clear

答案 1 :(得分:0)

Looking at the documentation,你不能只重置cookie jar属性吗?

e.g。

$w->cookie_jar({});