Use Python to send Renren on campus (Renren View status) _python

Source: Internet
Author: User

#_ *_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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.