使用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,因?yàn)樾枰猽rlencode()
req = urllib2.Request(
url,
urllib.urlencode(postdata)
)
self.file = urllib2.urlopen(req).read()
# urlopen后 成功后進(jìn)入首頁 因此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 '剛才賬號(hào) %s發(fā)了一條狀態(tài)' % self.email
print '內(nèi)容為: %s' % postdata.get('content', '')
renrenspider = spider('qich555550@163.com', 'qishibo123')
renrenspider.login()
#content = raw_input('請(qǐng)輸入狀態(tài)的內(nèi)容:')
contents =["祝","各","位","同","學(xué)","盆","友","在","新","的","一","年","里","身","體","健","康","萬","事","如","意","不小心刷屏了,望大家諒解"]
#renrenspider.publish(content)
#content = "新年快樂"
#renrenspider.publish(content)
#renrenspider.publish(content.decode('gb2312').encode('utf-8'))
for content in contents:
renrenspider.publish(content)
用這個(gè)程序就可以發(fā)狀態(tài)刷屏了,只不過校內(nèi)的狀態(tài)不支持具體時(shí)間,看不出效果來,不然每隔兩秒一條狀態(tài)應(yīng)該會(huì)讓人驚訝的
相關(guān)文章
python使用正則表達(dá)式(Regular Expression)方法超詳細(xì)
這篇文章主要介紹了python使用正則表達(dá)式(Regular Expression)方法超詳細(xì),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-12-12
Python實(shí)現(xiàn)網(wǎng)絡(luò)自動(dòng)化eNSP
這篇文章主要介紹了Python實(shí)現(xiàn)網(wǎng)絡(luò)自動(dòng)化eNSP,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-05-05
python 時(shí)間戳與格式化時(shí)間的轉(zhuǎn)化實(shí)現(xiàn)代碼
這篇文章主要介紹了python 時(shí)間戳和格式化時(shí)間的轉(zhuǎn)化,需要的朋友可以參考下2016-03-03
詳解python中@classmethod和@staticmethod方法
在python類當(dāng)中,經(jīng)常會(huì)遇到@classmethod和@staticmethod這兩個(gè)裝飾器,那么到底它們的區(qū)別和作用是啥子呢?本文結(jié)合場(chǎng)景分析給大家詳細(xì)講解,感興趣的朋友跟隨小編一起看看吧2022-10-10
python實(shí)現(xiàn)將list拼接為一個(gè)字符串
這篇文章主要介紹了python實(shí)現(xiàn)將list拼接為一個(gè)字符串方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-11-11
詳解Python list和numpy array的存儲(chǔ)和讀取方法
這篇文章主要介紹了詳解Python list和numpy array的存儲(chǔ)和讀取方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-11-11
python反反爬蟲技術(shù)限制連續(xù)請(qǐng)求時(shí)間處理
這篇文章主要為大家介紹了python反反爬蟲技術(shù)限制連續(xù)請(qǐng)求時(shí)間處理,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-06-06
這三個(gè)好用的python函數(shù)你不能不知道!
作為21世紀(jì)最流行的語言之一,Python當(dāng)然有很多有趣的功能值得深入探索和研究.今天通過理論和實(shí)際例子來討論,需要的朋友可以參考下2021-06-06
pytorch實(shí)現(xiàn)CNN卷積神經(jīng)網(wǎng)絡(luò)
這篇文章主要為大家詳細(xì)介紹了pytorch實(shí)現(xiàn)CNN卷積神經(jīng)網(wǎng)絡(luò),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-02-02

