我想解析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代码如下,
我正在尝试使用以下代码提取Wide character in print at ..
和其他详细信息
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 "$textn";
}
}
}
此代码引发警告look_down
CC_4需要属性/值参数对。
$a->look_down('_tag','span', 'class')
应该只是
$a->look_down('_tag','span')
我建议在脚本开头添加"use utf8;",以在打印中添加支持非ASCII符号。符号 • 是恭敬的宽。
use utf8;