使用python在校内发人人网状态(人人网看状态)_python
#_*_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的更多相关文章
- Python学习day35-并发编程(1)
figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...
- python(30) 获取网页返回的状态码,状态码对应问题查询
获取访问网页返回的状态码 html = requests.get(Url) respon = html.status_code 以下内容来自于维基百科:点击查看网页 1xx消息 这一类型的状态码,代表 ...
- Python+requests 发送简单请求--》获取响应状态--》获取请求响应数据
Python+requests 发送简单请求-->获取响应状态-->获取请求响应数据 1.环境:安装了Python和vscode编译器(Python自带的编译器也ok).fiddler抓包 ...
- Python学习day40-并发编程(终)
figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...
- Python学习day39-并发编程(各种锁)
figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...
- Python学习day38-并发编程(线程)
figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...
- Python学习day37-并发编程(3)
figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...
- Python学习day36-并发编程(2)
figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...
- HTTP 无状态啊无状态啊
无状态的根本原因 根本原因是:因为,HTTP协议使用的是Socket套接字TCP连接的,每次监听到的套接字连接是不可能一个个保存起来的.(很消耗资源,假如一个人服务器只保存一个通信连接,一万个岂不是要 ...
随机推荐
- 查询日志logcat使用总结
cmd命令行中使用adb logcat命令查看Android系统和应用的log,dos窗口按ctrl+c中断输出log记录.logcat日志中的优先级/tag标记: android输出的每一条日志都有 ...
- AutoIt 脚本1
一.新建的AU3 脚本进行编辑 选择Edit Script 如果是相运行脚本可以用Run Script 如果是想将脚本编译成.exe 可以用Compile Script 1)一个简单的AU3脚本 Ma ...
- 【Orange Pi Lite2】 ——1《如何开始使用开源硬件》
[Orange Pi Lite2] --1<如何开始使用开源硬件> 本文只在博客园发布 在开始前你需要准备的材料与软件 用户手册_Orange Pi Lite2 OrangePi_Lite ...
- C#实现灰度图像和彩色图像的4种镜像
一:灰度图像的水平镜像核心代码: 二:灰度图像的竖直镜像 核心代码:三:彩色图像的水平镜像 核心代码: 四:彩色图像的竖直镜像 核心代码:
- 第011课_串口(UART)的使用
from: 第011课_串口(UART)的使用 第001节_辅线1_硬件知识_UART硬件介绍 1. 串口的硬件介绍 UART的全称是 Universal Asynchronous Receiver ...
- windows自定义快速启动(运行)命令
自定义运行(windows键+R)里面命令,启动设置的程序,如图: 它的设置方法有两种: 第一种设置方法: 第1步:在任意地方创建一个文件夹(建议在D盘根目录创建),文件夹的名称可自定义没有特殊限制, ...
- Hbase 完全分布式 高可用 集群搭建
1.准备 Hadoop 版本:2.7.7 ZooKeeper 版本:3.4.14 Hbase 版本:2.0.5 四台主机: s0, s1, s2, s3 搭建目标如下: HMaster:s0,s1(备 ...
- MFC:DISP_FUNCTION 参数
/*#include <afxdisp.h>DISP_FUNCTION( theClass, pszName, pfnMember, vtRetVal, vtsParams )参数:the ...
- 字符串 -----JavaScript
本文摘要:http://www.liaoxuefeng.com/ JavaScript的字符串就是用''或""括起来的字符表示. 如果'本身也是一个字符,那就可以用"&q ...
- STL容器之Array[转]
转自https://blog.csdn.net/sin_geek/article/details/51067874 作者 Sin_Geek 简介 array在头文件<array> 中定义 ...