#!coding:utf-8
#导入需要的requests
import requests
#定义请求头
reqheaders={
'Content-type'
:
'application/x-www-form-urlencoded'
,
'Accept'
:
'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
,
'Host'
:
'www.renren.com'
,
'Origin'
:
'http://zhichang.renren.com'
,
'Referer'
:
'http://zhichang.renren.com'
,
'User-Agent'
:
'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1'
,}
#定义post的参数,requests模块,参数不用编码
reqdata={
'email'
:
'xxxx@xxx.com'
,
'password'
:
'xxxx'
,
'autoLogin'
:
'on'
,
'origURL'
:
'http://zhichang.renren.com/?login_state=rr'
,
'domain'
:
'renren.com'
}
#模拟post请求,不让自动重定向
res=requests.post(
"http://www.renren.com/PLogin.do"
,data=reqdata,headers=reqheaders,allow_redirects=False)
#模拟post请求,这个是自动重定向
#res=requests.post(
"http://www.renren.com/PLogin.do"
,data=reqdata,headers=reqheaders)
#打印服务器返回的状态
print
(res.status_code)
#打印服务器返回的内容
print
(res.content)
#打印重定向的URL地址
print
(res.headers[
'Location'
])
#打印服务器返回的cookie
print
(res.headers[
'Set-Cookie'
])