#_*_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. Android(java)学习笔记130:Android中操作XML数据(使用Pull解析器)

    1. Pull解析器的运行方式与 SAX 解析器相似.它提供了类似的事件,如:开始元素和结束元素事件,使用parser.next()可以进入下一个元素并触发相应事件.跟SAX不同的是, Pull解析器 ...

  2. JavaScript BOM DOM 对象

    title: JavaScript BOM DOM 对象 tags: JavaScript --- browser object model document onject model BOM对象 w ...

  3. Python 继承实现的原理(继承顺序)

    继承顺序 Python3 : 新式类的查找顺序:广度优先 新式类的继承: class A(object): Python2 3 都是了 MRO算法--生成一个列表保存继承顺序表 不找到底部 Pytho ...

  4. 【转】实用API大全

    有道翻译APIhttp://fanyi.youdao.com/openapi有道翻译API支持中英互译,同时获得有道翻译结果和有道词典结果(可能没有),返回格式为XML或JSON. 百度翻译APIht ...

  5. Ab initio methods|Evidence-based methods|maximum-likelihood|branch-site|H1|H0|GO|dS/dN ratio

    (Gene prediction and comparison) 使用基于基因组序列的从头预测方法(Ab initio methods)(同时分别使用头预测软件( GENSCAN和 AUGUSTUS) ...

  6. c#自定义类型之间的转换(强制类型转换)

    public class ResultModel { public string PlateNumber { get; set; } public int PlateColor { get; set; ...

  7. Bootstrap历练实例:带表格的面板

    带表格的面板 为了在面板中创建一个无边框的表格,我们可以在面板中使用 class .table.假设有个 <div> 包含 .panel-body,我们可以向表格的顶部添加额外的边框用来分 ...

  8. linux 下使用 curl 访问带多参数,GET掉参数解决方案

    url 为 http://mywebsite.com/index.php?a=1&b=2&c=3 web形式下访问url地址,使用 $_GET是可以获取到所有的参数 curl  -s  ...

  9. iOS应用架构谈part4-本地持久化方案及动态部署

    前言 嗯,你们要的大招.跟着这篇文章一起也发布了CTPersistance和CTJSBridge这两个库,希望大家在实际使用的时候如果遇到问题,就给我提issue或者PR或者评论区.每一个issue和 ...

  10. UIKeyboardType

    typedef NS_ENUM(NSInteger, UIKeyboardType) { UIKeyboardTypeDefault, // Default type for the current ...