• 根据body的内容 查找ul标签的@class="subtitle"的值


    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"的值

  • 相关阅读:
    es6学习笔记
    vue.js项目目录结构说明
    js 数组操作总结
    js 数组去重方法
    HTTP协议三次握手过程
    MVC与MVVM模式对比
    谱面编辑器
    LL谱面分析和难度标定
    SLP的模块结构
    LL基本姿势
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349808.html
Copyright © 2020-2023  润新知