使用 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_valuen";
}
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_valuen";
}
}
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_valuen";
}
}
当我从命令行运行文件时收到错误"无法在@INC中找到auto/HTML/TreeBuilder/new_from_ur.al(@INC包含:C:/Perl/lib C:/Perl/site/lib .)在 finaldisplay.pl 行 8"
首先检查最新版本的模块HTML::TreeBuilder
。尝试从 cpan
.
cpan -i HTML::TreeBuilder