标签:read pen decode rtk next mozilla put install request
import urllib.request,http.cookiejar,urllib.parse,re
print(‘start to login‘)
url=‘http://www.renren.com/PLogin.do‘
logindomain=‘renren.com‘
user_agent=‘Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.44 Safari/537.36 OPR/24.0.1558.25 (Edition Next)‘
myheader={‘User-Agent‘:user_agent,
‘Host‘:‘www.renren.com‘,
‘GET‘:url}
#msg=input(‘please your msg:‘)
msg=‘hello,everyone,I come from pythonClient.This is just a test\n陈耀烨力量很强‘
cj=http.cookiejar.CookieJar()
opener=urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
urllib.request.install_opener(opener)
values={‘email‘:‘18782938709‘,
‘password‘:‘******‘,
‘domain‘:logindomain}
data=urllib.parse.urlencode(values)
data=data.encode(‘utf-8‘)
req=urllib.request.Request(url,data,headers=myheader)
response=urllib.request.urlopen(req)
#print(response)
responselate=response.read().decode(‘utf-8‘)
#print(responselate)
reInfo = re.compile(r"get_check:‘(.*?)‘,get_check_x:‘(.*?)‘.*?‘id‘:‘(.*?)‘", re.DOTALL)
info = reInfo.findall(responselate)
myid= info[0][2]
print(myid)
tok= info[0][0]
print(tok)
rtk= info[0][1]
print(rtk)
url1=‘http://shell.renren.com/‘+myid+‘/status‘
values1={‘content‘:msg,
‘hostid‘:myid,
‘requestToken‘:tok,
‘_rtk‘:rtk,
‘channel‘:‘renren‘
}
data1=urllib.parse.urlencode(values1)
data1=data1.encode(‘utf-8‘)
myheader1={‘User-Agent‘:user_agent,
‘Host‘:‘shell.renren.com‘,
‘Origin‘:‘http://shell.renren.com‘,
‘Referer‘:‘http://shell.renren.com/ajaxproxy.htm‘,
‘POST‘:url1}
req1=urllib.request.Request(url1,data1,headers=myheader1)
response1=urllib.request.urlopen(req1).read()
print(‘you have broadcasted a status using your renrenAcount‘)
标签:read pen decode rtk next mozilla put install request
原文地址:http://www.cnblogs.com/gaokuan/p/6703124.html