使用python登录人人网并发表状态

把Email和password改成你的人人账号

#-*- coding:UTF-8 -*-
02'''
03======================================
04此程序根据 http://www.oschina.net/code/snippet_148170_10661 内容改编
05Adapted BY: bepcao
06Mail:peterc9511@gmail.com
07======================================
08'''
09 from sgmllib import SGMLParser
10 import sys,urllib2,urllib,cookielib
11 import datetime
12 import time
13 class spider(SGMLParser):
14     def __init__(self,email,password):
15         SGMLParser.__init__(self)
16         self.h3=False
17         self.h3_is_ready=False
18         self.div=False
19         self.h3_and_div=False
20         self.a=False
21         self.depth=0
22         self.names=""
23         self.dic={}  
24           
25         self.email=email
26         self.password=password
27         self.domain='renren.com'
28         try:
29             cookie=cookielib.CookieJar()
30             cookieProc=urllib2.HTTPCookieProcessor(cookie)
31         except:
32             raise
33         else:
34             opener=urllib2.build_opener(cookieProc)
35             urllib2.install_opener(opener)      
36 
37     def login(self):
38         print '开始登录'
39         url='http://www.renren.com/PLogin.do'
40         postdata={
41                   'email':self.email,
42                   'password':self.password,
43                   'domain':self.domain 
44                   }
45         req=urllib2.Request(
46                             url,
47                             urllib.urlencode(postdata)           
48                             )
49          
50         self.file=urllib2.urlopen(req).read()
51         idPos = self.file.index("'id':'")
52         self.id=self.file[idPos+6:idPos+15]
53         tokPos=self.file.index("get_check:'")
54         self.tok=self.file[tokPos+11:tokPos+21]
55         rtkPos=self.file.index("get_check_x:'")
56         self.rtk=self.file[rtkPos+13:rtkPos+21]
57      
58 
59 
60     def publish(self,content):
61         url1='http://shell.renren.com/'+self.id+'/status'
62         postdata={
63                   'content':content,
64                   'hostid':self.id,
65                   'requestToken':self.tok,
66                   '_rtk':self.rtk,
67                   'channel':'renren',
68                   }
69         req1=urllib2.Request(
70                             url1,
71                             urllib.urlencode(postdata)           
72                             )
73         self.file1=urllib2.urlopen(req1).read()
74         print '%s:\n刚才使用你的人人账号 %s 发了一条状态\n内容为:(%s)'%(datetime.datetime.now(),self.email,postdata.get('content',''))
75 
76 
77 
78 renrenspider=spider('Email','Password')
79renrenspider.login()
80 content=raw_input('请输入状态的内容:')
81renrenspider.publish(content)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值