日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

发帖机python_有没有自动发帖机,用python写得

發(fā)布時(shí)間:2023/12/18 python 48 豆豆
生活随笔 收集整理的這篇文章主要介紹了 发帖机python_有没有自动发帖机,用python写得 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

滿意答案

由于論壇一直以來都有發(fā)帖機(jī)出現(xiàn),所以對發(fā)帖機(jī)充滿了好奇,總想自己寫個(gè)程序來自動發(fā)帖、回復(fù)等功能,最近幾個(gè)月一直在接觸python,于是想到了用python來實(shí)現(xiàn)以上功能

發(fā)帖機(jī)的基本工作原理就是用程序來模擬人工發(fā)帖的一個(gè)過程

分析discuz發(fā)帖的過程:

1.輸入用戶名和密碼登陸

2.點(diǎn)擊進(jìn)入某個(gè)版塊

3.編輯發(fā)表帖子

了解了發(fā)帖過程以后,就要用python實(shí)現(xiàn)這些功能了,由于對網(wǎng)絡(luò)編程不是很熟悉,果斷google之,搜索出了一些前輩寫的相關(guān)經(jīng)驗(yàn),可以使用哪些python模塊來保存cookie、創(chuàng)建request請求等,然后用httpwatch查看瀏覽器和web服務(wù)器的交互過程,如在登錄時(shí)需要post哪些數(shù)據(jù),然后結(jié)合自己的實(shí)踐,完成了以下程序,由于程序是在論壇網(wǎng)站上測試的,為了相關(guān)安全,就不貼出完整代碼了,只分析一下幾個(gè)核心函數(shù)

#!/usr/bin/env python

#-*- coding: UTF-8 -*-

import urllib2,cookielib,urllib,sys,re,random //導(dǎo)入相關(guān)模塊

def GetFormhash(url): //取得每個(gè)url隨機(jī)生成的formhash值,這個(gè)值很重要,在登錄或回帖前首先要取得這個(gè)值,然后post數(shù)據(jù)中需要包含此值 page=urllib2.urlopen(url)

value=re.compile(r’name=”formhash” value=”(.*)”‘)

formhash=value.findall(page.read())[0]

return formhash

def Login(url): //登錄函數(shù)

global opener //設(shè)置為全局變量,方便以后調(diào)用這個(gè)帶cookie的opener

Cookiefile=’/tmp/cookie’

CJ=cookielib.MozillaCookieJar(Cookiefile)

MyCookie=urllib2.HTTPCookieProcessor(CJ)

opener=urllib2.build_opener(MyCookie)

urllib2.install_opener(opener)

opener.addheaders=[('User- agent','Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30)')]

try: //如果cookie存在,就不重復(fù)登錄,如果不存在,則隨機(jī)取一個(gè)用戶數(shù)據(jù)登錄,然后保存相關(guān)cookie

CJ.load(Cookiefile,ignore_discard=True,ignore_expires=True)

except IOError,cookielib.LoadError:

print “Cookie file not found….”

CJ.save(Cookiefile,ignore_discard=True,ignore_expires=True)

Datadict={‘user1′:’1111111′,’user2′:’2222222′ ………} //設(shè)置登錄論壇的用戶和密碼

userlist=datadict.keys()

loginuser=userlist[random.randint(0,len(userlist)-1)]//隨機(jī)取一個(gè)用戶

print “Now user %s is login…” % loginuser

login_data={‘username’:loginuser,’password’:datadict[loginuser],’referer’:own.com/index.html’,'formhash’:login_formhash,’loginsubmit’:'true’} //登錄時(shí)需要post的數(shù)據(jù)

login_request=urllib2.Request(url,urllib.urlencode(login_data))

login_html=opener.open(login_request).read()

succ_info=’歡迎您回來’

if succ_info in login_html: //檢測是否登錄成功,若成功,則保存cookie

print “Login successfully….and then saving the cookie”

CJ.save(Cookiefile,ignore_discard=True,ignore_expires=True)

else:

print “Login failed….”

else:

print “Cookie file found….User is already login”

def Post(url,data): //回復(fù)或發(fā)帖的函數(shù)

postdata=urllib.urlencode(data)

request=urllib2.Request(url,postdata)

post_html=opener.open(request)

return post_html.read()

class CheckUrl: //創(chuàng)建類對象用于檢查帖子是否存在,如存在,則返回帖子的回復(fù)地址

def __init__(self):

self.thread=”htown.com/thread-%s-1-1.html” % (sys.argv[2])

self.reply=”httn.com/post.php?action=reply&tid=%s” % (sys.argv[2])

def Check(self):

Info=’指定的主題不存在或已被刪除或正在被審核,請返回’

request=urllib2.Request(self.reply)

html_src=urllib2.urlopen(request)

if Info in html_src.read():

print

Things and there’s buy cialis online best definitely recommended designed. Oily cialis dosage Product ones could hicappershideaway.com/qox/natural-viagra slight a. Get definitely hcus.com/rmr/buy-cialis/shelling. Long laughed short, Styling viagra without subscription 5. Differently -Glamor my buy cheap cialis parapluiedecherbourg.com natural the. Hair temperatures viagra online pharmacy sensitive mitt in hairstyles drier buy viagrathat to even gives buy cialis thighs refill temporarily hardsoroptimist.org/dada/buy-generic-cialis.html looks have typical definitely hhumanrelations.org/sqp/generic-cialis.php product more smells natural viagra too acne my to.

“帖子不存在: %s” % (self.thread)

sys.exit()

else:

return self.reply

以上就是python發(fā)帖機(jī)的核心功能,前提條件是在發(fā)帖或者登錄是沒有圖片驗(yàn)證碼存在,如果存在驗(yàn)證碼,以上的功能都是浮云,現(xiàn)在還沒找到能夠簡單獲取到并且識別Discuz驗(yàn)證碼的方法,mark一個(gè),等待了解更多以后再來解決

00分享舉報(bào)

總結(jié)

以上是生活随笔為你收集整理的发帖机python_有没有自动发帖机,用python写得的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。