以上是我的代码来解析html表中的内容,我可以获取单元格,但我不知道如何获取内容,任何人都可以帮忙?谢谢!
my $te = new HTML::TableExtract( attribs => { id => 'friends' } );
$te->parse( $mech->content() ); #parse contents
my @tables = $te->tables;
my $table_count = scalar @tables;
print "tables count:$table_count\n";
my $table = $te->first_table_found;
print "table\n";
my @rows = $table->rows;
print "rows count:".scalar @rows."\n";
my $last_row=$rows[21];
print "last_row\n";
my $cell = $last_row->[2];
print "cell\n";
print $cell, "\n";
使用上面的代码print $cell, "\n";
,我得到了:
SCALAR(0x12a4bc4)
并使用此print $cell->content_refs_list, "\n";
,我得到了:
Can't call method "content_refs_list" on unblessed reference
单元格中的实际内容:
Page<strong>1</strong>/Total<strong>10</strong>Pages, <strong>100</strong>friends
答案 0 :(得分:3)
您不希望得到$cell
,想要获得$cell->as_HTML
或$cell->as_text
。
如您所知,直接访问$ cell可以获得对该对象的引用。你可能想要其他一些人类可读的内容。
答案 1 :(得分:0)
my $te = new HTML::TableExtract( attribs => { id => 'friends' } );
$te->parse( $mech->content() ); #parse contents
my @tables = $te->tables;
my $table_count = scalar @tables;
print "tables count:$table_count\n";
my $table = $te->first_table_found;
my $res = $table->cell(21,2);
print $res;