为什么WWW :: Mechanize失败,出现“X-Died:Illegal field name”X-Meta-Twitter:title'“?
问题描述:
为什么WWW::Mechanize
在获得以下URL后有空白内容?使用浏览器或curl
检索完整的HTML页面。为什么WWW :: Mechanize失败,出现“X-Died:Illegal field name”X-Meta-Twitter:title'“?
use WWW::Mechanize;
$mech = new WWW::Mechanize;
$mech->get("http://www.belizejudiciary.org/web/judgements2/");
print $mech->content # prints nothing
这里是响应的转储:
HTTP/1.1 200 OK
Connection: close
Date: Fri, 10 Feb 2017 00:51:47 GMT
Server: Apache/2.4
Content-Type: text/html; charset=UTF-8
Client-Aborted: die
Client-Date: Fri, 10 Feb 2017 00:51:48 GMT
Client-Peer: 98.129.229.64:80
Client-Response-Num: 1
Client-Transfer-Encoding: chunked
Link: <http://www.belizejudiciary.org/web/wp-json/>; rel="https://api.w.org/"
Link: <http://www.belizejudiciary.org/web/?p=468>; rel=shortlink
Set-Cookie: X-Mapping-hepadkon=FAB86566672CEB74D66B2818CA030616; path=/
X-Died: Illegal field name 'X-Meta-Twitter:title' at /usr/local/lib/perl5/site_perl/5.16.3/sun4-solaris/HTML/HeadParser.pm line 207.
X-Pingback: http://www.belizejudiciary.org/web/xmlrpc.php
我有HTML 3.70版本::分析器安装。
答
你转储显示,有解析响应的错误:
X-死于非法字段名 'X-元推特:标题' 是/ usr/local/lib目录/ perl5的/ SITE_PERL/5.16.3/sun4-的Solaris/HTML/HeadParser.pm线路207
这是由bug在HTML :: HeadParser造成的:
<meta>
标签可以有名称用冒号属性在他们中,这是完全有效的。但HTML :: HeadParser然后尝试使用HTTP :: Headers将它们注册为X-Meta-<name>
标头。较新版本的HTTP :: Headers(自6.05版本)对标题进行了更严格的检查,如果它们包含冒号,它们将拒绝它们。
这已经在HTML-Parser发行版的3.71版中得到修复,因此您应该升级。
我没有得到任何东西。你使用什么版本的模块? '使用Data :: Dumper的内容是什么;打印Dumper($ mech-> response)'? – choroba
@choroba我的系统有3.70版本的HTML:Parser,所以这可能是一个问题。查看我的编辑回复。 – CJ7
@choroba在'get'解决问题之前添加'$ mech-> parse_head(0)'。从这个答案:http://*.com/a/17745491/327528 – CJ7