Ωme*_*ega 0 javascript cookies perl http-referer lwp
我的抓取工具的简单代码是:
#!/usr/bin/perl -w
use WWW::Scripter;
$w = new WWW::Scripter('agent' => 'myAgent');
$w->use_plugin('JavaScript');
### need to set a referrer header here ###
$w->get('http://website-url');
print $w->content, "\n";
Run Code Online (Sandbox Code Playgroud)
我需要在执行之前设置一个引用标头get.或者我还需要设置其他标题,例如cookie等.我在文档中没有看到如何做到这一点.必须有一种方法,如何设置标题.怎么样?
WWW :: Scripter是WWW :: Mechanize的子类,因此您也应该能够使用该类的方法.它应该是这样的:
use strict; #ALWAYS do this
use warnings; #This too. Allows more control than -w
use WWW::Scripter;
#MODULE->new() is better than new Module() because of possible parsing ambiguity
my $w = WWW::Scripter->new('agent' => 'myAgent');
$w->add_header( Referer => 'http://somesite.com' );
$w->get('http://website-url');
Run Code Online (Sandbox Code Playgroud)