• perl 每次需要输入验证码 登录网站


    use Net::SMTP;
    use LWP::UserAgent;
    use HTTP::Cookies;
    use HTTP::Headers;
    use HTTP::Response;
    use Encode;
    use Switch;
    use File::Temp qw/tempfile/;
    use HTTP::Date qw(time2iso str2time time2iso time2isoz);
    my $CurrTime = time2iso(time());
    my $ua = LWP::UserAgent->new;
    $ua->timeout(10);
    $ua->env_proxy;
    my $now          = time();
    $ua->agent('Mozilla/5.0');
    my $cookie_jar = HTTP::Cookies->new(
    
        file           => 'lwp_cookies.txt',
        autosave       => 1,
        ignore_discard => 1
    );
    $ua->cookie_jar($cookie_jar);
    ##https://www.awfae.com/validcode/generate-validcode.do?0.36789621218278434
    my $response = $ua->get("https://www.awfae.com/validcode/generate-validcode.do");
    if ($response->is_success) {
       $r = $response->decoded_content;   
       # print $response->decoded_content;  # or whatever
    }
    else {
     die $response->status_line;
    };
    my ( $fh, $filename ) =
      tempfile( "wj_qrcode_XXXX", SUFFIX => ".jpg", DIR => 'c:\' );
    binmode $fh;
    print $fh $r;
    close $fh;
    print "登录二维码已经下载到本地 [ $filename ] 
    ";
    
    ##打开图片
    system("start $filename ");
    my $validCode = <STDIN>;
    chomp $validCode ;
     my $login_url = 'https://www.awfae.com/business/dispatch_post.do';
                    
     my $res = $ua->post($login_url,{
    	                       'action'=>'doLogin',
                              'userName'=>'18072722237',
    						  'followId'=>'',
                              'userPass'=>'79e8fe9f46221a9283d0c9263a',
                              'validCode'=> "$validCode"
                                                    });
    			 print "---------------
    ";
    
    my $head =$res->header('Location');	
    ;				
    print $res->header('Location');	
    print "
    ";	
    
    my $response = $ua->get("$head");
    if ($response->is_success) {
      #print $response->content; 
      $r = $response->content;   
    
    $str=encode("gbk",decode("utf8","$r"));
    print "$str == $str
    ";
    }
    my $now          = time();
    my $url="https://www.awfae.com/web/auth?method=%2Fwze%2Ftransfer%2Fcash%2Fin&amount=0.1&tradePassword=79e8fe923f031f46221a9283d0c9263a&_=$now";
    my $response = $ua->get("$url");
    if ($response->is_success) {
    #print $response->content; 
    $r = $response->content;   
    
    $str=encode("gbk",decode("utf8","$r"));
    print "$str is $str
    ";
    }
    
    ##http://www.awfae.com/login.html?info=u767bu5f55u5931u8d25u003au7528u6237
    ##http://www.awfae.com/login.html?info=登录失败:用户
    ##http://www.awfae.com/account/myAccount.html?subPage=/account/dashBoard.html&uuid=20150925104158452da9e0c7979d4438&
    
    # 响应头:
    # 原始头信息
    # Connection	
    # close
    # Content-Language	
    # zh-CN
    # Content-Length	
    # 0
    # Date	
    # Fri, 01 Sep 2017 00:57:34 GMT
    # Location	
    # https://www.awfae.com/account/myAccount.html?subPage=/account/dashBoard.html&uuid=20150925104158452da9e0c7979d4438
    # &
    # Server	
    # Apache-Coyote/1.1
    # Set-Cookie	
    # rememberMe=deleteMe; Path=/; Max-Age=0; Expires=Thu, 31-Aug-2017 00:57:34 GMT
    # X-Frame-Options	
    # SAMEORIGIN
    

  • 相关阅读:
    Vue.2.0.5-混合
    Vue.2.0.5-自定义指令
    Vue.2.0.5-过渡状态
    Vue.2.0.5-深入响应式原理
    spring mvc + mybatis + spring aop声明式事务管理没有作用
    Spring注解@Component、@Repository、@Service、@Controller区别
    继承之后的使用注意事项_ArrayStoreException
    java 中打印调用栈
    禁止 favicon.ico 请求
    mysq时间戳最小值
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349566.html
Copyright © 2020-2023  润新知