0

私のクローラーの簡単なコードは次のとおりです。

      #!/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ます。または、 cookieなどの他のヘッダーも設定する必要があります。ドキュメントにはその方法がありません。ヘッダーを設定する方法が必要です。どのように?

4

2 に答える 2

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');
于 2012-03-05T15:21:24.467 に答える
1

これはWWW::Mechanizeso のサブクラスです:

$w->add_header(Referer => "http://...");
于 2012-03-05T15:18:11.410 に答える