#_ *_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 ' Start login '
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, the introduction of URLLIB2 will require the introduction of urllib, because the need to UrlEncode ()
req = Urllib2. Request (
Url
Urllib.urlencode (PostData)
)
Self.file = Urllib2.urlopen (req). Read ()
# Urlopen After successful entry to the homepage so self.file content is the content of the home page HTML 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://www.bsck.org/' +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 ' The account%s has just sent a status '% Self.email
print ' contents:%s '% postdata.get (' content ', ')
Renrenspider = Spider (' [email protected] ', ' qishibo123 ')
Renrenspider.login ()
#content = raw_input (' Please enter the contents of the state: ')
Contents =["Wish", "each", "bit", "Same", "learn", "pots", "Friends", "in", "new", "the", "One", "year", "Li", "body", "body", "jian", "Kang", "Million", "things", "such as", "meaning", "careless brush screen, hope everyone understanding"]
#renrenspider. Publish (content)
#content = Bachelor Cinema "Happy New Year"
#renrenspider. Publish (content)
#renrenspider. Publish (Content.decode (' gb2312 '). Encode (' Utf-8 '))
For content in Contents:
Renrenspider.publish (content)
Use this program can send state brush screen, but the state of the school does not support the specific time, see no effect, or every two seconds a state should be surprised
Use Python to send Renren status on campus (Renren View status) _python