2012-03-05 6 views
0

シンプルなコードは次のとおりです。perlでWWW :: Scripterモジュールを使用して参照元を設定するには?私のクローラーのための

 #!/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"; 

私はgetが実行される前リファラヘッダーを設定する必要があります。あるいは、クッキーなどの他のヘッダーも設定する必要があります。documentationには表示されません。ヘッダーを設定する方法が必要です。どうやって?

答えて

5

WWW::ScripterWWW::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'); 
+0

私はそれが単純でなければならないことを知っていました。ありがとうございました! –

1

これには、WWW::Mechanizeのサブクラスである:

$w->add_header(Referer => "http://..."); 
+0

ありがとう、ガンババス。 –

関連する問題