Use python to post status of renren on campus
- 2020-04-02 13:26:33
- OfStack
#_*_coding:utf_8_
from sgmllib import SGMLParser
import sys, urllib2, urllib, cookielib
import datetime, time
class spider(SGMLParser):
def __init__(self, email, password):
SGMLParser.__init__(self)
self.email = email
self.password = password
self.domain = 'renren.com'
try:
cookie = cookielib.CookieJar()
# a class to handle HTTP cookies
cookieProc = urllib2.HTTPCookieProcessor(cookie)
except:
raise
else:
opener = urllib2.build_opener(cookieProc)
urllib2.install_opener(opener)
def login(self):
print ' To log in '
url = 'http://www.renren.com/PLogin.do'
#url = 'http://www.renren.com/SysHome.do'
postdata = {
'email': self.email,
'password': self.password,
'domain': self.domain
}
# In general urllib2 All need to be introduced urllib, Because of the need to urlencode()
req = urllib2.Request(
url,
urllib.urlencode(postdata)
)
self.file = urllib2.urlopen(req).read()
# urlopen after Enter the home page after success so self.file Is the content of the home page html Contents of the file
# print self.file
idPos = self.file.index("'id':'")
self.id = self.file[idPos+6:idPos+15]
tokPos = self.file.index("get_check:'")
self.tok = self.file[tokPos+11:tokPos+21]
rtkPos = self.file.index("get_check_x:'")
self.rtk = self.file[rtkPos+13:rtkPos+21]
def publish(self, content):
url1 = 'http://shell.renren.com/' +self.id+ '/status'
print 'self.id = ' , self.id
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 datetime.datetime.now()
print ' Just account %s I posted a status ' % self.email
print ' Content is : %s' % postdata.get('content', '')
renrenspider = spider('qich555550@163.com', 'qishibo123')
renrenspider.login()
#content = raw_input(' Please enter the contents of the status: ')
contents =[" I wish "," each "," position "," with "," learn "," The basin "," friends "," in "," new "," the "," one "," years "," In the "," The body "," The body of the "," health "," kang "," wan "," things "," Such as "," meaning "," I'm not careful refresh , I hope you can understand. "]
#renrenspider.publish(content)
#content = " Happy New Year! "
#renrenspider.publish(content)
#renrenspider.publish(content.decode('gb2312').encode('utf-8'))
for content in contents:
renrenspider.publish(content)
Use this program to send status refresh, but the state of the school does not support the specific time, do not see the effect, or every two seconds a state should be surprising