我正在使用HTML::Query从每个 td 标签中提取内容。我确实想要 html 格式的。现在当我打印它时,它似乎打印了两次,大部分时间。有什么想法吗?这是我正在使用的代码:
for my $td ($doc->query("td")) {
$td= $td->as_HTML;
given($td){
when (/class=\"class1\">(.*?)<\/td>/){
my $output = $1;
print "$output\n";
}
when (/class=\"class2\">(.*?)<\/td>/){
my $output = $1;
print "$output\n";
}
when (/class=\"class3\">(.*?)<\/td>/){
my $output = $1;
print "$output\n";
}
when (/class=\"class4\">(.*?)<\/td>/){
my $output = $1;
print "$output\n";
}
}
Input:
<table>
<tr>
<td class="class1">question</td>
<td class="class2">No response</td>
</tr>
<tr>
<td class="class1">question</td>
<td class="class2">No response</td>
</tr>
<tr>
<td class="class3">Answer</td>
<td class="class4">Answer is available</td>
</tr>
</table>