Use python to publish the Renren status on Campus (Renren status)

Source: Internet
Author: User

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.

Related Article

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.