如何手动将cookie添加到WWW :: Mechanize已经存在的cookiejar中(how do I manually add cookies to WWW::Mechanize's

编程入门 行业动态 更新时间:2024-10-28 11:32:47
如何手动将cookie添加到WWW :: Mechanize已经存在的cookiejar中(how do I manually add cookies to WWW::Mechanize's already existing cookiejar)

我有一个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".

更多推荐

本文发布于:2023-07-30 08:01:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1336681.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Mechanize   cookiejar   cookie   WWW   cookies

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!