perl 登录盈盈理财

#!/usr/bin/perl

use LWP;
use LWP::Simple;
use LWP::UserAgent;
use HTTP::Cookies;
use HTTP::Headers;
use HTTP::Response;
use utf8;
use Encode;
use URI::Escape;
use URI::URL;
use Data::Dumper;

my $cell="XXX";
my $password="XXX";
my $token='';
my $var='';

my $ua = LWP::UserAgent->new;
$ua->agent("Mozilla/5.0 (Windows NT 6.1; rv:30.0) Gecko/20100101 Firefox/30.0");

my $cookie_jar=HTTP::Cookies->new(
        file=>'lwp_cookies.txt',
        autosave=>1,
        ignore_discard=>1
        );
$ua->cookie_jar($cookie_jar);

my $login_url="https://licai.yingyinglicai.com/user/loginByPwd.do";

my $res = $ua->get($login_url);

if( $res->is_success ) {
        $var = $res->decoded_content;
        if ($var =~/.*token"\s+value="(.*?)"/.*/)  {
                print "\$1 is $1\n"; 
                $token=$1; 
        }
}

$res = $ua->post($login_url,{
                'cell'=>$cell,
                'password'=>$password,
                'token'=>$token
        });

print $res->header('Location'),"\n";

if( $res->header('Location') eq 'http://licai.yingyinglicai.com/index.htm' ) {
        print "YES";
        $homepage = $ua->get('https://licai.yingyinglicai.com/index.htm');
        open YY, '>yinyin.html';
        print YY $homepage->decoded_content;
        close YY;
}

你可能感兴趣的:(perl 登录盈盈理财)