简体   繁体   English

如何在许多WWW :: Mechanize运行中维护cookie?

[英]How do I maintain cookies across many WWW::Mechanize runs?

use WWW::Mechanize;
use strict;
my $agent = WWW::Mechanize->new(cookie_jar => {ignore_discard => 0});
$agent->add_header('User-Agent' => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:20.0) Gecko/20100101 Firefox/20.0');
$agent->get($url);
my $content = $agent->content;

The cookie_jar attribute expects a HTTP::Cookies object. cookie_jar属性需要一个HTTP :: Cookies对象。

WWW::Mechanize->new(
    cookie_jar => HTTP::Cookies->new(
        file => 'lwp_cookies.dat',
        autosave => 1,
    )
)

Your mistake was to declare a plain hashref, this means a temporary in-memory cookie store that is destroyed after Mechanize ends. 您的错误是声明了一个普通的hashref,这意味着一个临时的内存cookie存储在Mechanize结束后被销毁了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM