我有一个perl脚本,在获取页面后,我需要将cookie添加到已经存在cookie的已经存在的cookiejar中。 我该怎么做呢? 我希望有一个python机械化样式.set_cookie()函数
I have a perl script where after fetching a page I need to add a cookie to an already existing cookiejar with cookies in it already. how do I go about doing this? I'm hoping for a python mechanize style .set_cookie() function
最满意答案
WWW :: Mechanize对象是一个 LWP :: UserAgent ,它有一个cookie_jar属性,通常包含一个HTTP :: Cookies对象,它有一个set_cookie方法。
所以你要做的事情如下:
$mech->cookie_jar->set_cookie( $version, $key, $val, $path, $domain, $port, $path_spec, $secure, $maxage, $discard, \%rest )set_cookie()方法更新$ cookie_jar的状态。 $ key,$ val,$ domain,$ port和$ path参数是字符串。 $ path_spec,$ secure,$ discard参数是布尔值。 $ maxage值是一个数字,表示此cookie将存在的秒数。 值<= 0将删除此cookie。 %rest定义了各种其他属性,如“Comment”和“CommentURL”。
A WWW::Mechanize object isa LWP::UserAgent, which has a cookie_jar attribute that normally contains a HTTP::Cookies object, which has a set_cookie method.
So you'd do something like:
$mech->cookie_jar->set_cookie( $version, $key, $val, $path, $domain, $port, $path_spec, $secure, $maxage, $discard, \%rest )The set_cookie() method updates the state of the $cookie_jar. The $key, $val, $domain, $port and $path arguments are strings. The $path_spec, $secure, $discard arguments are boolean values. The $maxage value is a number indicating number of seconds that this cookie will live. A value <= 0 will delete this cookie. %rest defines various other attributes like "Comment" and "CommentURL".
更多推荐
发布评论