【发布时间】:2021-08-06 19:03:45
【问题描述】:
使用HTML::Parser(或任何其他可以提供相同功能的东西,最好对文档源有一定的容忍度)如何转储特定元素节点的内容以跟踪其中的变化?
例如,给定一个文档:
<body>
<div id="foo">
<div id="bar">
</div>
</div>
</body>
我需要在这段代码中添加什么才能对bar 中的所有内容进行哈希处理?
use HTML::Parser;
sub foo {
my $tag = shift;
if ($tag ne "div") {
return;
}
my $attrs = shift;
my @ids = split(/ /, $attrs->{'id'});
if (grep(/bar/, @ids)) {
print "how do I sha256() the innerhtml here?";
}
}
my $p = HTML::Parser->new(
start_h => [\&foo, 'tagname, attr'],
);
$p->parse_file('index.html');
减少到解释源就足够了。
【问题讨论】:
-
你试过什么?你有什么问题?请向我们展示您的代码。
-
这样的问题Mojo::DOM就足够了。