HTML::TreeBuilder::XPath 添加XPath 支持HTML::TreeBuilder
use HTML::TreeBuilder::XPath;
my $tree= HTML::TreeBuilder::XPath->new;
$tree->parse_file( "mypage.html");
my $nb=$tree->findvalue( '/html/body//p[@class="section_title"]/span[@class="nb"]');
my $id=$tree->findvalue( '/html/body//p[@class="section_title"]/@id');
my $p= $html->findnodes( '//p[@id="toto"]')->[0];
my $link_texts= $p->findvalue( './a'); # the texts of all a elements in $p
$tree->delete; # to avoid memory leaks, if you parse many HTML documents
描述:
use HTML::TreeBuilder::XPath;
my $tree= HTML::TreeBuilder::XPath->new;
$tree->parse_file( "mypage.html");
my $nb=$tree->findvalue( '/html/body//p[@class="section_title"]/span[@class="nb"]');
my $id=$tree->findvalue( '/html/body//p[@class="section_title"]/@id');
my $p= $html->findnodes( '//p[@id="toto"]')->[0];
my $link_texts= $p->findvalue( './a'); # the texts of all a elements in $p
$tree->delete; # to avoid memory leaks, if you parse many HTML documents
描述: