根据input 标签取value属性的值

jrhmpt01:/root/lwp/0526# cat a1.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( "0526.txt");
my    @pages=$tree->find_by_tag_name('input');
                      #@urlall除了包含每个类别的文章,还包含阅读排行里的文章
                      foreach (@pages) {
                                               @titlepage = $_->attr('value');
                                               foreach (@titlepage) {
                                                 if ($_){ 
                                                print "\$_ is $_\n";
                                                     };
                                           };
};
jrhmpt01:/root/lwp/0526# cat 0526.txt 
<input name="csrfmleawretoken" type="hidden" value="fs34fgsdfsdfsdfsfsfs"/> <input name="csrfmleawretoken" type="hidden" value="scan3131313"/>
jrhmpt01:/root/lwp/0526# perl a1.pl 
$_ is fs34fgsdfsdfsdfsfsfs
$_ is scan3131313

posted @ 2016-05-28 09:47  czcb  阅读(497)  评论(0编辑  收藏  举报