[root@master test]# cat 3.pl
#!/usr/bin/perl
# Copyright 2014 tkorays. All rights reserved.
# author tkorays
# email tkorays@hotmail.com
use strict;
use warnings;
use LWP;
use LWP::Simple;
use LWP::UserAgent;
use HTTP::Cookies;
use HTTP::Headers;
use HTTP::Response;
use Encode;
use URI::Escape;
use URI::URL;
my $email = 'zhao.yangjian@163.com';
my $password = 'xxxxx';
my $domain = 'renren.com';
my $hostid='';
my $requestToken='';
my $rtk='';
my $channel='renren';
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 = 'http://www.renren.com/PLogin.do';
# 这里面没有判断是否需要验证码,聪明的你学完后肯定知道怎么搞定的
# 人人是post登陆的,第一个参数是登陆的地址,第二个参数是一个匿名hash
my $res = $ua->post($login_url,{
'email'=>$email,
'password'=>$password,
'domain'=>$domain});
my $homepage;
# 判断响应头里面的location,确定是否登陆成功
print "---------------\n";
print $res->header('Location');
print "---------------\n";
if($res->header('Location') eq 'http://www.renren.com/Home.do'){
print 'login ok...',"\n";
$homepage = $ua->get('http://www.renren.com/home');
}else{
exit;
}
[root@master test]# perl 3.pl
---------------
http://www.renren.com/Home.do---------------
login ok...
perl 登入人人网
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
下一篇:perl 自定义请求头
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章