タイトルの通りWWW::Mechanizeが認識しない
<base href="" />
ページ コンテンツが gzip されている場合。次に例を示します。
use strict;
use warnings;
use WWW::Mechanize;
my $url = 'http://objectmix.com/perl/356181-help-lwp-log-after-redirect.html';
my $mech = WWW::Mechanize->new;
$mech->get($url);
print $mech->base()."\n";
# force plain text instead of gzipped content
$mech->get($url, 'Accept-Encoding' => 'identity');
print $mech->base()."\n";
出力:
http://objectmix.com/perl/356181-help-lwp-log-after-redirect.html
http://objectmix.com/ <--- this is correct !
ここで何か不足していますか?ありがとう
編集: LWP::UserAgent で直接テストしたところ、問題なく動作します。
use LWP::UserAgent;
my $ua = LWP::UserAgent->new();
my $res = $ua->get('http://objectmix.com/perl/356181-help-lwp-log-after-redirect.html');
print $res->base()."\n";
出力:
http://objectmix.com/
これは WWW::Mechanize のバグのように見えますか?
編集 2: WWW::Mechanize ではなく、LWP または HTTP::Response のバグです。LWP はデフォルトで gzip を要求しません。私が設定した場合
$ua->default_header('Accept-Encoding' => 'gzip'),
上記の例では、間違ったベースを返します
編集 3: バグは parse_head() の LWP/UserAgent.pm にあります
gzip された HTML を使用して HTML/HeadParser を呼び出しますが、HeadParser はそれをどう処理するかわかりません。LWP は、解析サブルーチンを呼び出す前にコンテンツをガンジップする必要があります。