我正在尝试从几个 HTML 文件中删除所有表格元素。
以下代码在单个文件上完美运行,但在尝试自动化该过程时,它返回错误
无法对未定义的值调用方法“look_down”
请问您有什么解决办法吗?
这是代码:
use strict;
use warnings;
use Path::Class;
use HTML::TreeBuilder;
opendir( DH, "C:/myfiles" );
my @files = readdir(DH);
closedir(DH);
foreach my $file ( @files ) {
print("Analyzing file $file\n");
my $tree = HTML::TreeBuilder->new->parse_file("C:/myfiles/$file");
foreach my $e ( $tree->look_down( _tag => "table" ) ) {
$e->delete();
}
use HTML::FormatText;
my $formatter = HTML::FormatText->new;
my $parsed = $formatter->format($tree);
print $parsed;
}