jrhmpt01:/root/lwp# cat data.html jrhmpt01:/root/lwp# cat c1.pl use LWP::UserAgent;use DBI; use POSIX;use Data::Dumper;use HTML::TreeBuilder;my $ua = LWP::UserAgent->new;$ua->timeout(10);$ua->env_proxy;$ua->agent("Mozilla/8.0"); use HTML::TreeBuilder::XPath; $tree= HTML::TreeBuilder::XPath->new; $tree->parse_file( "data.html");my @title= $tree->findvalues('/html/body//a[@class="changePage"]');print "\@title is @title\n";jrhmpt01:/root/lwp# perl c1.pl@title is 首页 上一页 11 首页 上一页 11my @title= $tree->findvalue('/html/body//a[@class="changePage"]');表示 根据body的内容 查找a标签的@class="changePage"的值jrhmpt01:/root/lwp# cat c1.pl use LWP::UserAgent;use DBI; use POSIX;use Data::Dumper;use HTML::TreeBuilder;my $ua = LWP::UserAgent->new;$ua->timeout(10);$ua->env_proxy;$ua->agent("Mozilla/8.0"); use HTML::TreeBuilder::XPath; $tree= HTML::TreeBuilder::XPath->new; $tree->parse_file( "data.html");my @pages=$tree->find_by_tag_name('a'); #@urlall除了包含每个类别的文章,还包含阅读排行里的文章 foreach (@pages) { @titlepage = $_->attr('page'); foreach (@titlepage) { if ($_){ print "\$_ is $_\n"; }; };};jrhmpt01:/root/lwp# perl c1.pl $_ is 1$_ is 11$_ is 11$_ is 1$_ is 11$_ is 11根据a标签,查看page属性的值