在Perl中手动设置Cookie_jar?

时间:2013-12-02 21:04:50

标签: javascript perl cookies setcookie lwp

我一直在尝试用LWP::ParanoidAgent打开一个页面,但由于它没有解析或评估显然需要的JavaSript以打开页面(I get some <noscript>... Not supporting Cookie ... Javascript, you must turn them on</noscript>),所以我之前看到过加载文档,它确实运行此脚本

<script type="text/javascript">
            document.cookie="DDOS_IXI=e77ddbe96ca229ef0b16d5214b9d6670; max-age=604800; path=/";
            var nc = function() {return document.cookie.indexOf("DDOS_IXI=e77ddbe96ca229ef0b16d5214b9d6670")==-1;};
            var w = function() {document.body.innerHTML = document.getElementsByTagName("noscript")[0].textContent;};
            if (!window.opera) {
                    if (!nc()) {window.location.reload(true);}
                    var r = function() {if (nc()) w();};
            } else {
                    var r = function () {
                            if (!nc()) {window.location.reload(true);}
                            else {w();}
                    }
            }
</script>

所以我认为如果我手动设置cookie会有效,所以我写了一个正则表达式来获取像这样的my ($cookie) = $response->decoded_content =~ /document\.cookie="(.*?)"/的cookie然后我这样设置:

my $cookies = HTTP::Cookies->new();
$cookies->add_cookie_header($cookie);

$ua->cookie_jar($cookies);
$request = GET $topic;
$response = $ua->request($request);

但我确实收到以下错误:

Can't locate object method "uri" via package "DDOS_IXI=e77ddbe96ca229ef0b16d5214b9d6670; max-age=604800; path=/" (perhaps you forgot to load "DDOS_IXI=e77ddbe96ca229ef0b16d5214b9d6670; max-age=604800; path=/"?) at /usr/share/perl5/HTTP/Cookies.pm line 42.

提前致谢。

0 个答案:

没有答案