• 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($_);
           };
      };
    };
    		
  • 相关阅读:
    HighTec-Eclipse for Tricore 的安装方法
    http升级https遇到的问题
    symfony中模板生成路径两种方式
    http请求在https中使用
    git tag标签
    Git查看两个版本之间修改了哪些文件
    mysql将语句写入表中
    使用fiddler抓包模拟器及配置fiddler过滤
    Mixed Content: The page at 'xxx' was loaded over HTTPS, but requested an insecure resource 'xxx'.
    nginx 禁止某IP访问
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13348999.html
Copyright © 2020-2023  润新知