我有一个充满链接的 .html 文件,我想提取没有 http:// 的域(所以只是链接的主机名部分,例如 blah.com)列出它们并删除重复项。
到目前为止,这就是我想出的-我认为问题在于我尝试传递 $tree 数据的方式
#!/usr/local/bin/perl -w
use HTML::TreeBuilder 5 -weak; # Ensure weak references in use
use URI;
foreach my $file_name (@ARGV) {
my $tree = HTML::TreeBuilder->new; # empty tree
$tree->parse_file($file_name);
my $u1 = URI->new($tree);
print "host: ", $u1->host, "\n";
print "Hey, here's a dump of the parse tree of $file_name:\n";
# Now that we're done with it, we must destroy it.
# $tree = $tree->delete; # Not required with weak references
}