Copy codeThe Code is as follows:
# _ * _ 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 t:
Raise
Else:
Opener = urllib2.build _ opener (cookieProc)
Urllib2.install _ opener (opener)
Def login (self ):
Print 'start logon'
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, urllib must be introduced when urllib2 is introduced, because urlencode () is required ()
Req = urllib2.Request (
Url,
Urllib. urlencode (postdata)
)
Self. file = urllib2.urlopen (req). read ()
# After urlopen succeeds, the homepage is displayed. Therefore, the content of self. file is the html file of the homepage.
# 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. SCN = 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,
'_ Mns': self. mns,
'Channel': 'renren ',
}
Req1 = urllib2.Request (
Url1,
Urllib. urlencode (postdata)
)
Self. file1 = urllib2.urlopen (req1). read ()
Print datetime. datetime. now ()
Print 'account % s sent a status '% self. email
Print 'content: % s' % postdata. get ('content ','')
Renrenspider = spider ('qich555550 @ 163.com ', 'qishibo123 ')
Renrenspider. login ()
# Content = raw_input ('Enter the status content :')
Contents = ["zhu", "", "bit", "same", "", "basin", "friends", "in", "new ", "," 1 "," year "," Li "," body "," body "," jian "," Kang "," Ten Thousand "," things ", "such as", "meaning", "accidentally screen-flushing, hope you 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)
You can use this program to screen the status, but the status in the school does not support the specific time and the effect is not displayed. Otherwise, the status will be surprising every two seconds.