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 ] \n";

##打开图片
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 "---------------\n";

my $head =$res->header('Location');	
;				
print $res->header('Location');	
print "\n";	

my $response = $ua->get("$head");
if ($response->is_success) {
  #print $response->content; 
  $r = $response->content;   

$str=encode("gbk",decode("utf8","$r"));
print "\$str == $str\n";
}
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\n";
}

##http://www.awfae.com/login.html?info=\u767b\u5f55\u5931\u8d25\u003a\u7528\u6237\
##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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

scan724

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值