【问题标题】:Why does WWW::Mechanize fail with "X-Died: Illegal field name 'X-Meta-Twitter:title'"?为什么 WWW::Mechanize 失败并显示“X-Died: Illegal field name 'X-Meta-Twitter:title'”?
【发布时间】:2017-02-10 00:35:17
【问题描述】:

为什么WWW::Mechanize得到以下网址后内容为空白?使用浏览器或curl 检索到完整的 HTML 页面。

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

我安装了 3.70 版的 HTML::Parser。

【问题讨论】:

  • 我什么也没得到。您使用什么版本的模块? use Data::Dumper; print Dumper($mech-&gt;response)的内容是什么?
  • @choroba 我的系统有HTML:Parser 的3.70 版,所以这可能是个问题。请参阅我的编辑以获取回复。
  • @choroba 在get 之前添加get 解决了问题。从这个答案:stackoverflow.com/a/17745491/327528
  • 我觉得这是您找到的that other SO question 的副本,但这些答案都有待改进。我的意思是,猴子修补 HTML::HeadParser?完全禁用标头解析?真的吗?
  • @ThisSuitIsBlackNot 我认为这是将问题标记为重复的问题。

标签: perl curl www-mechanize


【解决方案1】:

您的转储显示解析响应时出错:

X-Died:/usr/local/lib/perl5/site_perl/5.16.3/sun4-solaris/HTML/HeadParser.pm 第 207 行的非法字段名称“X-Meta-Twitter:title”。

这是由 HTML::HeadParser: 中的 bug 引起的:

&lt;meta&gt; 标签可以包含带有冒号的名称属性,这是完全有效的。但是 HTML::HeadParser 然后尝试使用 HTTP::Headers 将这些注册为 X-Meta-&lt;name&gt; 标头。较新版本的 HTTP::Headers(自 6.05 起)对标头进行更严格的检查,如果它们包含冒号,则会拒绝它们。

这已在 HTML-Parser 发行版的 3.71 版中修复,因此您应该升级。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-11-29
    • 2020-12-04
    • 2018-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-27
    相关资源
    最近更新 更多