0

使用 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 行"

4

1 回答 1

1

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

cpan -i HTML::TreeBuilder

于 2012-09-27T12:18:05.330 回答