perl - Perl HTML::Treebuilder::Xpath无法找到子标记

标签 perl xpath

HTML结构是

<div class="profile-content"><section class="content-section"><h3 class="subheader">Welcome to the party</h3>


我要列印


欢迎来到派对


代码如下

my $profile= $tree->findvalue('//div[@class="profile-content"]/section[@class="content-section"]/h3[@class="subheader"]');


但是它没有打印任何东西。

请帮我。

问候

最佳答案

<section>是HTML5标记,HTML :: TreeBuilder无法识别。默认情况下,它不存在于HTML的内部表示中。

ignore_unknown选项设置为0(false)应该可以为您提供所需的内容。

看到不同:

> perl -MHTML::TreeBuilder -E'my $t=HTML::TreeBuilder->new; $t->parse( q{<div class="profile-content"><section class="content-section"><h3 class="subheader">Welcome to the party</h3>}); say $t->as_HTML'
<html><head></head><body><div class="profile-content"><h3 class="subheader">Welcome to the party</h3></div></body></html>

> perl -MHTML::TreeBuilder -E'my $t=HTML::TreeBuilder->new; $t->ignore_unknown( 0); $t->parse( q{<div class="profile-content"><section class="content-section"><h3 class="subheader">Welcome to the party</h3>}); print $t->as_HTML'
<html><head></head><body><div class="profile-content"><section class="content-section"><h3 class="subheader">Welcome to the party</h3></section></div></body></html>

关于perl - Perl HTML::Treebuilder::Xpath无法找到子标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32630111/

相关文章:

perl - 当反引号命令失败时如何在 Perl 中获取错误消息

perl - 如何运行由 Module::Starter 构建的新 Perl 程序?

php - 使用 DOMXPath 在 <p> 标签内保留换行符?

python - 如何将Pandas read_xml设置为特定节点?

mysql - Perl 从 xls 读取插入到 mysql

perl - 我们如何使用 Perl::Tidy 或 Perl::Critic 捕捉旁注?

javascript - XPath .evaluate() 不返回任何内容

css - 无法从 xpath 获取值

Perl foreach 循环只打印一行

selenium - href 元素的 Xpath