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/