我正在尝试使用 HTML::TableExtract 从 html 文件中提取表格内容。我的问题是我的 html 文件的结构如下:
<!DOCTYPE html>
<html>
<body>
<h4>One row and three columns:</h4>
<table border="1">
<tr>
<td>
<p> 100 </p></td>
<td>
<p> 200 </p></td>
<td>
<p> 300 </p></td>
</tr>
<tr>
<td>
<p> 100 </p></td>
<td>
<p> 200 </p></td>
<td>
<p> 300 </p></td>
</tr>
</table>
</body>
</html>
由于这种结构,我的输出看起来像:
100|
200|
300|
400|
500|
600|
而不是我想要的:
100|200|300|
400|500|600|
你能帮忙吗?这是我的perl代码
use strict;
use warnings;
use HTML::TableExtract;
my $te = HTML::TableExtract->new();
$te->parse_file('Table_One.html');
open (DATA2, ">TableOutput.txt")
or die "Can't open file";
foreach my $ts ($te->tables()) {
foreach my $row ($ts->rows()) {
my $Final = join('|', @$row );
print DATA2 "$Final";
}
}
close (DATA2);