#_*_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 '开始登录'
        url = 'http://www.renren.com/PLogin.do'
        #url = 'http://www.renren.com/SysHome.do'
        postdata = {
                    'email': self.email,
                    'password': self.password,
                    'domain': self.domain  
                   }
        # 一般情况下引入urllib2的地方都需要引入urllib,因为需要urlencode()
        req = urllib2.Request(
                              url,
                              urllib.urlencode(postdata)            
                             )

self.file = urllib2.urlopen(req).read()
        # urlopen后 成功后进入首页 因此self.file的内容就是首页的html文件的内容
        # 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 '刚才账号 %s发了一条状态' % self.email  
        print '内容为: %s' % postdata.get('content', '')

renrenspider = spider('qich555550@163.com', 'qishibo123')
renrenspider.login()
#content = raw_input('请输入状态的内容:')
contents =["祝","各","位","同","学","盆","友","在","新","的","一","年","里","身","体","健","康","万","事","如","意","不小心刷屏了,望大家谅解"]
#renrenspider.publish(content)
#content =光棍影院 "新年快乐"
#renrenspider.publish(content)
#renrenspider.publish(content.decode('gb2312').encode('utf-8'))

for content in contents:
    renrenspider.publish(content)

用这个程序就可以发状态刷屏了,只不过校内的状态不支持具体时间,看不出效果来,不然每隔两秒一条状态应该会让人惊讶的

使用python在校内发人人网状态(人人网看状态)_python的更多相关文章

  1. Python学习day35-并发编程(1)

    figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...

  2. python(30) 获取网页返回的状态码,状态码对应问题查询

    获取访问网页返回的状态码 html = requests.get(Url) respon = html.status_code 以下内容来自于维基百科:点击查看网页 1xx消息 这一类型的状态码,代表 ...

  3. Python+requests 发送简单请求--》获取响应状态--》获取请求响应数据

    Python+requests 发送简单请求-->获取响应状态-->获取请求响应数据 1.环境:安装了Python和vscode编译器(Python自带的编译器也ok).fiddler抓包 ...

  4. Python学习day40-并发编程(终)

    figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...

  5. Python学习day39-并发编程(各种锁)

    figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...

  6. Python学习day38-并发编程(线程)

    figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...

  7. Python学习day37-并发编程(3)

    figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...

  8. Python学习day36-并发编程(2)

    figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...

  9. HTTP 无状态啊无状态啊

    无状态的根本原因 根本原因是:因为,HTTP协议使用的是Socket套接字TCP连接的,每次监听到的套接字连接是不可能一个个保存起来的.(很消耗资源,假如一个人服务器只保存一个通信连接,一万个岂不是要 ...

随机推荐

  1. Ubuntu 11.04 安装 cuda5.0

    由于实验需要,于2016年10月15日再Ubuntu11.04安装cuda5.0,但是从网上查找Ubuntu11.04 只有对应的支持的cuda4 版本,cuda 5.0前面版本不支持IDE nisg ...

  2. Hadoop 2.7.0模拟分布式实验环境搭建[亲测]

    实验目的: 本实验通过在PC电脑上同时运行3个虚拟机,一个为master节点,两个slave节点.    搭建环境: 主机:mac os 10.10   OS:CenOS 6.5 虚拟机:VMware ...

  3. MySQL安装未响应解决方法

    安装MySQL出示未响应,一般显示在安装MySQL程序最后2步的3,4项就不动了. 这种情况一般是你以前安装过MySQL数据库服务项被占用了. 1.卸载MySQL 2.删除安装目录及数据存放目录 3. ...

  4. UVA 690 PipelineScheduling 位运算+dfs+剪枝

    一开始最容易想到间隔最多为n,但是结点还是太多了,需要优化. 预处理:预判一下并保存下一个可以放的位置距离之前的距离.这样可以减少很多判断. 最优化剪枝:如果当前长度+剩下没放的程序*最短间隔如果大于 ...

  5. appium---常用的adb命令

    在测试android-app的时候,adb命令可以帮助我们解决许多问题 什么是adb Android Debug Bridge,我们一般简称为adb,主要存放在sdk安装目录下的platform-to ...

  6. C# 替换去除HTML标记方法(正则表达式)

    [from] http://blog.csdn.net/sgear/article/details/6263848/// <summary> /// 将所有HTML标签替换成"& ...

  7. dht 分布式hash 一致性hash区别

    先有一致性hash :一致性哈希,似乎最早提出是在分布式缓存里面的,让节点震荡的时候,影响最小.不过现在已经应用在分布式存储和p2p系统里面. dht 是p2p领域的概念,内有三大概念是由keyspa ...

  8. NOIP模拟赛 经营与开发 小奇挖矿

    [题目描述] 4X概念体系,是指在PC战略游戏中一种相当普及和成熟的系统概念,得名自4个同样以“EX”为开头的英语单词. eXplore(探索) eXpand(拓张与发展) eXploit(经营与开发 ...

  9. MySql常用数据操作

    1.数据库操作: MySQL服务管理命令: 1.启动服务:sudo service mysql start 2.停止服务:sudo service mysql stop 3.重新启动服务:sudo s ...

  10. Springboot @Autowired 无法注入问题

    特别提醒:一定要注意文件结构 WebappApplication 一定要在包的最外层,否则Spring无法对所有的类进行托管,会造成@Autowired 无法注入. 1. 添加工具类获取在 Sprin ...