#encoding:utf-8
"""
This program is rewrite from http://www.oschina.net/code/snippet_946076_17870
"""
import urllib2, urllib, cookielib, datetime, re
class spider():
def __init__(self, email, password):
self.email = email
self.password = password
self.domain = 'renren.com'
try:
cookie = cookielib.CookieJar()
cookieProc = urllib2.HTTPCookieProcessor(cookie)
except:
raise
else:
opener = urllib2.build_opener(cookieProc)
urllib2.install_opener(opener)
def login(self):
print 'Loging in...'
url = 'http://www.renren.com/PLogin.do'
postdata = {
'email':self.email,
'password':self.password,
'domain':self.domain
}
req = urllib2.Request(url, urllib.urlencode(postdata))
self.file = urllib2.urlopen(req).read()
reInfo = re.compile(r"get_check:'(.*?)',get_check_x:'(.*?)'.*?'id':'(.*?)'", re.DOTALL)
info = reInfo.findall(self.file)
self.id = info[0][2]
self.tok = info[0][0]
self.rtk = info[0][1]
def publish(self, content):
url1 = 'http://shell.renren.com/' + self.id + '/status'
postdata = {
'content' : content,
'hostid' : self.id,
'requestToken': self.tok,
'_rtk' : self.rtk,
'channel' : 'renren'
}
req1 = urllib2.Request(url1, urllib.urlencode(postdata))
self.file1 = urllib2.urlopen(req1).read()
print 'U have post a message :%s' % content
user = raw_input('Renren.com User: ')
pswd = raw_input('Renren.com Password: ')
renrenspider = spider(user, pswd)
renrenspider.login()
content = raw_input('Please input your message :')
renrenspider.publish(content)
用Python登陆人人网并发状态(在已有基础上进行了修改)
最新推荐文章于 2023-06-20 17:59:51 发布