GetElementsByClassName - Perl?

时间:2013-09-23 14:55:01

标签: html perl

我正在尝试在Javascript中执行getElementsByClassName,在perl但是它不起作用,从下面的代码我得到的是END,它没有进入foreach循环,什么我做错了,有没有比HTML :: TagParser更好的方法?

...
my $html = HTML::TagParser->new( "****.html" );
$topic = URI::Fetch->fetch($topic);

my @list = $html->getElementsByClassName( 'separateur_links' );
foreach my $elem ( @list ) {
    my $text = $elem->innerText;
    print $text . "\n";
}
print "END\n";
...

编辑:

当我使用Data::Dumper print Dumper($html);时,我得到:$VAR1 = bless( {}, 'HTML::TagParser' );

编辑2:

$topic = URI::Fetch->fetch($topic); 不是原来的问题,我忽略了它不知道这是问题

1 个答案:

答案 0 :(得分:2)

问题出在URI::Fetch->fetch我用它进行其他测试而忘记删除它:

my $topic = "*******.html";
print "** Checking available links in : " . $topic . "\n";
# $topic = URI::Fetch->fetch($topic);

my $html = HTML::TagParser->new( $topic );
print Dumper($html);
my @list = $html->getElementsByClassName( 'separateur_links' );
foreach my $elem ( @list ) {
    my $text = $elem->innerText;
    print $text . "\n";
}