将Perl与LWP一起使用,对于以下HTML,如何搜索以获取开始标记和结束标记之间的文字字符串 < b> div 然后获取上述开始和结束标记之间的所有文本,而粘贴格式化文本标记
<div id="foo" class="blah">
<tt>
test
<br>test
<br>whatever
<br>test
</div>
要打印到STDOUT:
test
test
whatever
test
答案 0 :(得分:4)
$node->find_by_attribute(attribute, value) and $node->as_text()
答案 1 :(得分:2)
my @elms = $tree->look_down(
_tag => "div",
sub { $_[0]->as_text =~ /whatever/ },
);
for my $elm (@elms) {
print $elm->as_trimmed_text;
}