使用python在校內(nèi)發(fā)人人網(wǎng)狀態(tài)(人人網(wǎng)看狀態(tài))
#_*_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的內(nèi)容就是首頁的html文件的內(nèi)容
# 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://shell.renren.com/' +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發(fā)了一條狀態(tài)' % self.email
print '內(nèi)容為: %s' % postdata.get('content', '')
renrenspider = spider('qich555550@163.com', 'qishibo123')
renrenspider.login()
#content = raw_input('請輸入狀態(tài)的內(nèi)容:')
contents =["祝","各","位","同","學","盆","友","在","新","的","一","年","里","身","體","健","康","萬","事","如","意","不小心刷屏了,望大家諒解"]
#renrenspider.publish(content)
#content = "新年快樂"
#renrenspider.publish(content)
#renrenspider.publish(content.decode('gb2312').encode('utf-8'))
for content in contents:
renrenspider.publish(content)
用這個程序就可以發(fā)狀態(tài)刷屏了,只不過校內(nèi)的狀態(tài)不支持具體時間,看不出效果來,不然每隔兩秒一條狀態(tài)應(yīng)該會讓人驚訝的
相關(guān)文章
python使用正則表達式(Regular Expression)方法超詳細
這篇文章主要介紹了python使用正則表達式(Regular Expression)方法超詳細,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-12-12
Python實現(xiàn)網(wǎng)絡(luò)自動化eNSP
這篇文章主要介紹了Python實現(xiàn)網(wǎng)絡(luò)自動化eNSP,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2021-05-05
python 時間戳與格式化時間的轉(zhuǎn)化實現(xiàn)代碼
這篇文章主要介紹了python 時間戳和格式化時間的轉(zhuǎn)化,需要的朋友可以參考下2016-03-03
詳解python中@classmethod和@staticmethod方法
在python類當中,經(jīng)常會遇到@classmethod和@staticmethod這兩個裝飾器,那么到底它們的區(qū)別和作用是啥子呢?本文結(jié)合場景分析給大家詳細講解,感興趣的朋友跟隨小編一起看看吧2022-10-10
詳解Python list和numpy array的存儲和讀取方法
這篇文章主要介紹了詳解Python list和numpy array的存儲和讀取方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-11-11
python反反爬蟲技術(shù)限制連續(xù)請求時間處理
這篇文章主要為大家介紹了python反反爬蟲技術(shù)限制連續(xù)請求時間處理,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-06-06
pytorch實現(xiàn)CNN卷積神經(jīng)網(wǎng)絡(luò)
這篇文章主要為大家詳細介紹了pytorch實現(xiàn)CNN卷積神經(jīng)網(wǎng)絡(luò),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2020-02-02

