簡體   English   中英

為什么LWP :: UserAgent不能完全獲得這個網站?

[英]Why can't LWP::UserAgent get this site entirely?

它從一開始只輸出幾行。

#!/usr/bin/perl

use strict;
use warnings;
use LWP::UserAgent;

my $ua = LWP::UserAgent->new;
my $response = $ua->get('http://www.eurogamer.net/articles/df-hardware-wii-u-graphics-power-finally-revealed');
print $response->decoded_content;

我運行了以下修改:

my $response = $ua->get( 'http://www.eurogamer.net/articles/df-hardware-wii-u-graphics-power-finally-revealed' );
say $response->headers->as_string;

看到了這個:

Cache-Control: max-age=60s
Connection: close
Date: Wed, 06 Feb 2013 23:51:15 GMT
Via: 1.1 varnish
Age: 0
Server: Apache
Vary: Accept-Encoding
Content-Length: 50519
Content-Type: text/html; charset=ISO-8859-1
Client-Aborted: die
Client-Date: Wed, 06 Feb 2013 23:50:50 GMT
Client-Peer: 94.198.83.18:80
Client-Response-Num: 1
X-Died: Illegal field name 'X-Meta-Twitter:card' at .../HTML/HeadParser.pm line 207.
X-Varnish: 630361704

它似乎不喜歡第27行的<meta name="twitter:card" content="summary" />標簽。它說它已經死了。

它似乎將具有name屬性的任何meta標記轉換為"X-Meta-\\u$attr->{name}" “標題”。 然后,它嘗試將content屬性的值存儲為X-meta“header”值。 像這樣(從第194行開始):

if ($tag eq 'meta') {
    my $key = $attr->{'http-equiv'};
    if (!defined($key) || !length($key)) {
        if ($attr->{name}) {
            $key = "X-Meta-\u$attr->{name}"; # <-- Here's the little trick
        } elsif ($attr->{charset}) { # HTML 5 <meta charset="...">
            $key = "X-Meta-Charset";
            $self->{header}->push_header($key => $attr->{charset});
            return;
        } else {
            return;
        }
    }
    $self->{'header'}->push_header($key => $attr->{content});
}

我將此模塊的修改后的副本推送到PERL5LIB目錄中。 我將push_header步驟包裝在eval塊中並完全下載頁面。

我有完全相同的問題......

我修復了它,禁用了啟用HTML :: HeadParser的選項'parse_head'。

    $self->{ua}->parse_head(0);

我知道禁用此功能不是一個好主意,但我更喜歡可用性而不是正確的解碼文檔。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM