• perl 获取响应头


    use LWP::UserAgent;
    use HTTP::Cookies;
    use HTTP::Headers;
    use HTTP::Response;
    use Encode;
    use JSON;
    use File::Temp qw/tempfile/;
    use HTML::TreeBuilder::XPath;
    use Encode;      
    use HTML::TreeBuilder;       
    use Data::Dumper;   
    use HTML::TreeBuilder::XPath;     
    use DBI;     
    use Encode;
    use Data::Dumper;
    my $ua = LWP::UserAgent->new( ssl_opts => { verify_hostname => 0 }, );;
    $ua->timeout(5);
    $ua->env_proxy;
    print $ua->timeout;
    my $now          = time();
    $ua->agent('Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0');
    print $ua->agent;
    print "
    ";
    my $cookie_jar = HTTP::Cookies->new(
    
        file           => 'lwp_cookies002.txt',
        autosave       => 1,
        ignore_discard => 1
    );
    $ua->cookie_jar($cookie_jar);
    my $login_url = 'http://10.3.200.9/login/VerifyLogin.jsp';
    my $res = $ua->post($login_url,{
    	                  'formmethod'=>'post',
                              'logfile'=>'/wui/theme/ecology8/page/login.jsp?templateId=3&logintype=1&gopage=',
                              'loginid'=>'xx',
                              'logintype'=> '1',
    		          'submit'=>'腎翹',
    		         'userpassword'=>'xx'
                                                   });
    my $response = $ua->get('http://10.3.200.9/tailong/syslink/daohanglianjie.jsp');
    if ($response->is_success) {
        $r = $response->content;   
    }else {
     &SendSms('http://10.3.200.9/tailong/syslink/daohanglianjie.jsp'."->".$response->status_line);
     print 'http://10.3.200.9/tailong/syslink/daohanglianjie.jsp'."->".$response->status_line;
    };
    sub geturl{
       my $url=shift;
       print $url."
    ";
       my $response = $ua->get($url);
       if ($response->is_success) {
         $r = $response->content;
         print $r;
         print "
    ";
         sleep 3;
         if ($r=~/.*?window.open("(.*?)".*/){
           $xindai=$1;
           print  $xindai."
    ";
         };
         my $url01='http://20.2.200.17:7003'.$xindai;
         print $url01;
         print "
    ";
         sleep 2;
         my $response= $ua->get($url01);
         if ($response->is_success) {
    	    print 'tiao zhuan ye mian'."
    ";
            print $response->header('Date')."
    ";
    		print $response->header('Transfer-Encoding')."
    ";
    		print $response->header('Content-Type')."
    ";
    		print $response->header('Content-Language')."
    ";
    		print 'tiao zhuan ye mian'."
    ";
             sleep 3;
            }
         else
          {
          print $url01."->".$response->status_line."
    ";
          &SendSms($url01."->".$response->status_line);
         };
     }
     else {
       print $url."->".$response->status_line."
    ";
       &SendSms($url."->".$response->status_line);
        };
    };
    
    
    sub SendSms {
         my $message=shift;
         my $token_url= 'http://10.5.100.232:8080/tlcbspt/sendText';  
         $ua->default_headers;
         #$ua->get("http://10.3.172.15:3000/api/SMSsendx?sourceip=$IP&message=$message&phone=18072722237|17605860611|17605860662");
         $ua->get("http://10.5.100.232:8001/?message=$message&phone=18072722237");
           };
    
    
    open fh1,">fh1.html" || die "open csdn file failed:$!";  
     print fh1  $r;  
     close fh1;
    
    #my $tree= HTML::TreeBuilder::XPath->new; 
    #$tree->parse_file("fh1.html"); 
    #my @bumen = $tree->findvalues('//div/span'); 
    #foreach (@bumen){
    #  $_=~s/|//g;
    #  next if $_=~/^$/;
    #  print $_;
    #  print "
    ";
    #};
    
    my $tree= HTML::TreeBuilder::XPath->new;
    $tree->parse_file("fh1.html");
    my @xitong = $tree->findvalues('//div/a');
    foreach (@xitong){
    };
    
    ##??url
    $tree->parse_file( "fh1.html");
    #?????`?URL足??a???????href 
    @Links = $tree->find_by_tag_name('a'); 
      foreach (@Links) {  
          @Href = $_->attr('href');
          $i++;
          foreach (@Href){
           next unless ($_=~/^http/ or $_=~/^/tailong/);
           if ($_=~'http://20.2.200.17:7003/loan-web/4ALogon.jsp'){
           print $_;
           print "
    ";
           sleep 3;
           &geturl($_);
           };
      };
    };
    		
  • 相关阅读:
    mysql数据库题目【杭州多测师】【杭州多测师_王sir】
    python题目:维度为(M,N)求矩阵的转置【杭州多测师】【杭州多测师_王sir】
    python题目【杭州多测师】【杭州多测师_王sir】
    购物车测试点【杭州多测师】【杭州多测师_王sir】
    史上最全软件测试工程师常见的面试题总结【杭州多测师】【面试题】【杭州多测师_王sir】
    查询"001"课程比"002"课程成绩高的所有学生的学号【杭州多测师】【杭州多测师_王sir】
    mysql数据库查询当天,最近7天,最近1个月数据【杭州多测师】【杭州多测师_王sir】
    python题目:判断一个IP地址是否合法【杭州多测师】【杭州多测师_王sir】
    sql floor()函数
    mysql左连右连
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13348999.html
Copyright © 2020-2023  润新知