我想解析 html 页面。使用提取徽章、描述和徽章类型
<div class="row">
<div class="span8">
<table id="badge-list">
<tr>
<td style="width: 25px;"></td>
<td style="width: 200px;" class="badge-cell">
<a class="badge-name" href="/badge/show/3/">
<span class="badge-icon bronze">•</span>
Editor
</a>
<span class="multiplier">x 3892</span></td>
<td class="earned False"> </td>
<td>First edit</td>
</tr>
我的 perl 代码如下,
我正在尝试 a class="badge-name"
使用以下代码提取和其他细节
my $tree = HTML::TreeBuilder->new();
$tree->parse($content);
my ($h1) = $tree->look_down('_tag', 'table', 'id', 'badge-list');
my @tr = $h1->look_down('_tag', 'tr') ;
foreach my $tr (@tr) {
my @tdList = $tr->look_down('_tag','td');
foreach my $td ( @tdList) {
if (my $a = $td->look_down('_tag','a')) {
print $a->as_text , "\n";
my $span = $a->look_down('_tag','span', 'class');
print $span->attr('class');
}
else {
my $text = $td->as_text , "\n";
print "$text\n";
}
}
}
此代码正在引发警告Wide character in print at ..