• perl 使用cookie


    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);
    
    if ( $cookie_jar){
    $cookie_jar->load( $cookie_jar );
    my $now          = time();
    my $url="https://wenjinbao.winfae.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
    ";
    
    
    
    if ($str =~/用户未登录/){
        my $response = $ua->get("https://wenjinbao.winfae.com/validcode/generate-validcode.do?$str");
    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 ;
    print "$validCode is $validCode
    ";
    
    #my $url="https://wenjinbao.winfae.com/business/dispatch_post.do";
    
     my $login_url = 'https://wenjinbao.winfae.com/business/dispatch_post.do';
                    
     my $res = $ua->post($login_url,{
    	                       'action'=>'doLogin',
                              'userName'=>'18072722237',
    						  'followId'=>'',
                              'userPass'=>'xxxxxxxxxx',
                              'validCode'=> "$validCode"
                                                    });
    			 print "---------------
    ";
    
    my $head =$res->header('Location');	
    ;				
    print $res->header('Location');	
    print "
    ";	
    
    					
    print $res->status_line."
    ";
    print "11111111111111111111
    ";
    print $res->as_string();#获取的是原始内容,包括响应头,响应正文
    print "11111111111111111111
    ";
    my $content=$res->content();  
    #print $res->content();            #获取的是响应正文
    
    my $spool = encode("gbk",decode("utf8","$content"));	
    #print "$spool is $spool
    ";
      print "
    ";
    
    my $response = $ua->get("$head");
    if ($response->is_success) {
    #print $response->content; 
      $r = $response->content;   
    
    $str=encode("gbk",decode("utf8","$r"));
    print "$str is $str
    ";
    
    my $now          = time();
    my $url="https://wenjinbao.winfae.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
    ";
    
    }else
       { $r = $response->content;  
       print $response->content; 
                           };
    	
                           };
    
                           };
    	                   };
                   
    	                   };			
    	 			
    
    

  • 相关阅读:
    Redis-数据类型
    文件转二进制流拆分与组装
    word 文件转PDF 预览
    查询数据库还原时间
    Window10主机连接到Docker 中的mysql 数据库
    sqlServer 执行存储过程结果存表中
    启动mysql 镜像
    Java类型转换细节
    IDEA常用插件
    IDEA控制台中文乱码
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13350626.html
Copyright © 2020-2023  润新知