• 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; 
                           };
    	
                           };
    
                           };
    	                   };
                   
    	                   };			
    	 			
    
    

  • 相关阅读:
    hadoop中namenode发生故障的处理方法
    开启虚拟机所报的错误:VMware Workstation cannot connect to the virtual machine. Make sure you have rights to run the program, access all directories the program uses, and access all directories for temporary fil
    Hbase的安装与部署(集群版)
    分别用反射、编程接口的方式创建DataFrame
    用Mapreduce求共同好友
    SparkSteaming中直连与receiver两种方式的区别
    privot函数使用
    Ajax无刷新显示
    使用ScriptManager服务器控件前后台数据交互
    数据库知识
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13350626.html
Copyright © 2020-2023  润新知