perl中的HTML :: TreeBuilder-> new_from_url()无法正常工作

时间:2012-09-27 11:08:42

标签: perl html-tree

使用HTML :: TreeBuilder-> new_from_url()想要访问一个网站https://abc.com/index.html,并希望显示该html页面中的一些值。

https://abc.com/index.html要求用户身份验证(test / test123是用户名和密码)。我使用了以下代码:文件名:finaldisplay.pl

  #!/usr/bin/perl

   use HTML::TreeBuilder;
   use HTML::Entities;


   my $url = "http://test:test123@abc.com:8080/index.html";
   my $tree = HTML::TreeBuilder->new_from_url($url);

   $tree->elementify;

   for my $post( $tree->look_down( _tag => q{tr}, 'class' => 'row-odd'  ) ) {

my $disk_value;
my $name = $post->look_down( _tag => q{td}, 'class' => 'stats_left');
    my $data = $name->as_trimmed_text;


 if($data =~ /Home Directory/){
$disk_value =   $post->look_down( _tag => q{td}, 'class' => 'stats_right' )->as_trimmed_text;
print STDERR "$data : $disk_value\n";
}
elsif($data =~ /Disk Space Usage/){
$disk_value = $post->look_down( _tag => q{td}, 'class' => 'stats_right' );
$disk_value = ($disk_value->content_list)[0];

$disk_value  = encode_entities($disk_value);

 print STDERR "$data : $disk_value\n";
}

}

for my $post( $tree->look_down( _tag => q{tr}, 'class' => 'row-even'  ) ) {

my ($disk_value, $disk);

my $name = $post->look_down( _tag => q{td}, 'class' => 'stats_left');
     my $data = $name->as_trimmed_text;

    if($data =~ /Main Domain/){
$disk = $post->look_down( _tag => q{td}, 'class' => 'stats_right' );
$disk_value = $post->look_down( _tag => q{b})->as_trimmed_text;
print STDERR "$data : $disk_value\n";
} 

 }

当我从命令行运行文件时收到错误“无法在@INC中找到auto / HTML / TreeBuilder / new_from_ur.al(@INC包含:C:/ Per l / lib C:/ Perl / site / lib。)在finaldisplay.pl第8行“

1 个答案:

答案 0 :(得分:1)

首先检查模块HTML::TreeBuilder的最新版本。 尝试从cpan安装它。

cpan -i HTML::TreeBuilder