用Python登陆人人网并发状态(在已有基础上进行了修改)

#encoding:utf-8
"""
This program is rewrite from http://www.oschina.net/code/snippet_946076_17870
"""
import urllib2, urllib, cookielib, datetime, re
class spider():
    def __init__(self, email, password):
        self.email = email
        self.password = password
        self.domain = 'renren.com'
        try:
            cookie = cookielib.CookieJar()
            cookieProc = urllib2.HTTPCookieProcessor(cookie)
        except:
            raise
        else:
            opener = urllib2.build_opener(cookieProc)
            urllib2.install_opener(opener)

    def login(self):
        print 'Loging in...'
        url = 'http://www.renren.com/PLogin.do'
        postdata = {
                    'email':self.email,
                    'password':self.password,
                    'domain':self.domain
                    }
        req       = urllib2.Request(url, urllib.urlencode(postdata))
        self.file = urllib2.urlopen(req).read()
        reInfo = re.compile(r"get_check:'(.*?)',get_check_x:'(.*?)'.*?'id':'(.*?)'", re.DOTALL)
        info = reInfo.findall(self.file)
        self.id   = info[0][2]
        self.tok  = info[0][0]
        self.rtk  = info[0][1]

    def publish(self, content):
        url1 = 'http://shell.renren.com/' + self.id + '/status'
        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 'U have post a message :%s' % content
        
user = raw_input('Renren.com User: ')
pswd = raw_input('Renren.com Password: ')
renrenspider = spider(user, pswd)
renrenspider.login()
content = raw_input('Please input your message :')
renrenspider.publish(content)

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值