python 实现 自动定时发送人人状态
2013-02-19 22:36
686 查看
2013.9.20 因为人人改版,可能已无法使用
#-*- coding:UTF-8 -*-'''======================================此程序根据 http://www.oschina.net/code/snippet_946076_17870 内容改编Adapted BY: jxyMail:czjxy8898@gmail.com======================================'''from sgmllib import SGMLParserimport sys,urllib2,urllib,cookielibimport datetimeimport timeclass spider(SGMLParser):def __init__(self,email,password):SGMLParser.__init__(self)self.h3=Falseself.h3_is_ready=Falseself.div=Falseself.h3_and_div=Falseself.a=Falseself.depth=0self.names=""self.dic={}self.email=emailself.password=passwordself.domain='renren.com'try:cookie=cookielib.CookieJar()cookieProc=urllib2.HTTPCookieProcessor(cookie)except:raiseelse:opener=urllib2.build_opener(cookieProc)urllib2.install_opener(opener)def login(self):print 'start login'url='http://www.renren.com/PLogin.do'postdata={'email':self.email,'password':self.password,'domain':self.domain}try:req=urllib2.Request(url,urllib.urlencode(postdata))self.file=urllib2.urlopen(req).read()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]print 'success'return 1except:print 'error'return 0def 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 '%s:\n %s have sended\n:(%s)'% (datetime.datetime.now(),self.email,postdata.get('content',''))def tt(T=5):while 1:t = time.localtime()content='24小时测试:现在时间'+str(t.tm_hour)+'时'+str(t.tm_min)+'分'+str(t.tm_sec)+'秒'print contentrenrenspider.publish(content)time.sleep(60)T=T-1if T==0:breakuser=raw_input('email or phone number:')password=raw_input('password:')renrenspider=spider(user,password)if renrenspider.login() :#content=raw_input('please input content:')# renrenspider.publish(content.decode('gb2312').encode('utf-8'))while 1:if time.localtime().tm_sec==0 and time.localtime().tm_min==0:tt(24)breaktime.sleep(1)
相关文章推荐
- Python实现自动发送邮件功能
- python实现自动发送微博,当自己写博客时同步上去。
- 利用python3 爬取教务处实现自动查询成绩并发送给用户QQ邮箱
- python 3.6 urllib库实现天气爬取、邮件定时给妹子发送天气
- Python实现定时备份mysql数据库并把备份数据库邮件发送
- 一个python的邮件发送脚本,自动,定时,可以附件发送,抄送,附有说明文件
- python实现人人自动回复、抢沙发功能
- Python小练习-自动登录人人发送消息并返回好友列表
- python 实现zabbix自动发送报表 推荐
- python简单实现服务器信息自动邮件发送
- python实现自动发送邮件发送多人、群发、多附件的示例
- python 实现邮件自动发送
- python学习===实现定时发送,方法一
- 最完整的自动化测试流程:Python编写执行测试用例及定时自动发送最新测试报告邮件
- python3.x实现自动发送邮件
- [linux & python] linux下基于python自动定时发送邮件附件
- Python实现定时备份mysql数据库并把备份数据库邮件发送
- 采用Python实现自动发送摄像头图片到微博
- python 实现 自动oa 签到签退 发送邮件提醒