码迷,mamicode.com
首页 > 其他好文 > 详细

人人爬取

时间:2017-04-13 11:52:09      阅读:156      评论:0      收藏:0      [点我收藏+]

标签: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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!