node2:/root/pachong#cat test.html
<ul class="panel_body">
<li>
<a href="/zhaoyangjian724/article/category/1756569" οnclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_wenzhangfenlei']); ">Oracle dump解析</a><span>(20)</span>
</li>
<li>
<a href="/zhaoyangjian724/article/category/1756685" οnclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_wenzhangfenlei']); ">sql 查询优化</a><span>(159)</span>
</li>
my @type=$tree->findvalues( '/html/body//ul[@class="panel_body"]/li/a');
findvalues ($path)
返回 匹配的值作为一个列表,这个和findnodes_as_strings很像,
除非列表的元素是对象
node2:/root/pachong#cat findvalues.pl
use LWP::UserAgent;
use POSIX;
use HTML::TreeBuilder::XPath;
use Encode;
use HTML::TreeBuilder;
use Data::Dumper;
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->env_proxy;
$ua->agent("Mozilla/8.0");
use HTML::TreeBuilder::XPath;
my $tree= HTML::TreeBuilder::XPath->new;
$tree->parse_file( "csdn.html");
##获取博客分类的URL,根据a标签查找
my @type=$tree->findvalues( '/html/body');
#my @type=$tree->findvalues( '/html/body//ul[@class="panel_body"]/li/a');
print @type;
node2:/root/pachong#perl findvalues.pl
Oracle dump解析(20)sql 查询优化(159)node2:/root/pachong#
根据body的内容 查找ul标签的@class="subtitle"的值