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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python 论坛自动发帖功能

發(fā)布時間:2023/12/18 python 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python 论坛自动发帖功能 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
# -*- coding: utf-8 -*- """ @author: amtsing """ ''' Google翻譯 ''' import execjsclass Py4Js(): def __init__(self): self.ctx = execjs.compile(""" function TL(a) { var k = ""; var b = 406644; var b1 = 3293161072; var jd = "."; var $b = "+-a^+6"; var Zb = "+-3^+b+-f"; for (var e = [], f = 0, g = 0; g < a.length; g++) { var m = a.charCodeAt(g); 128 > m ? e[f++] = m : (2048 > m ? e[f++] = m >> 6 | 192 : (55296 == (m & 64512) && g + 1 < a.length && 56320 == (a.charCodeAt(g + 1) & 64512) ? (m = 65536 + ((m & 1023) << 10) + (a.charCodeAt(++g) & 1023), e[f++] = m >> 18 | 240, e[f++] = m >> 12 & 63 | 128) : e[f++] = m >> 12 | 224, e[f++] = m >> 6 & 63 | 128), e[f++] = m & 63 | 128) } a = b; for (f = 0; f < e.length; f++) a += e[f], a = RL(a, $b); a = RL(a, Zb); a ^= b1 || 0; 0 > a && (a = (a & 2147483647) + 2147483648); a %= 1E6; return a.toString() + jd + (a ^ b) }; function RL(a, b) { var t = "a"; var Yb = "+"; for (var c = 0; c < b.length - 2; c += 3) { var d = b.charAt(c + 2), d = d >= t ? d.charCodeAt(0) - 87 : Number(d), d = b.charAt(c + 1) == Yb ? a >>> d: a << d; a = b.charAt(c) == Yb ? a + d & 4294967295 : a ^ d } return a } """) def getTk(self, text): return self.ctx.call("TL", text) import urllib.request, urllib.parsedef open_url(url): '''打開網(wǎng)頁鏈接''' headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64;rv:23.0)Gecko/20100101 Firefox/23.0'} req = urllib.request.Request(url=url, headers=headers) response = urllib.request.urlopen(req) data = response.read().decode('utf-8') return datadef translate(content): '''定義翻譯函數(shù)''' if len(content) > 4891: print("翻譯的長度超過限制!!!") return # 獲取tk if len(content) > 4891: print("翻譯的長度超過限制!!!") return js = Py4Js() tk = js.getTk(content) # 對輸入內(nèi)容編碼 content = urllib.parse.quote(content) url = "http://translate.google.cn/translate_a/single?client=t&sl=en&tl=zh-CN&hl=zh-CN&dt =at&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&ie=UTF-8&oe=UTF-8& source=bh&otf=1&ssel=0&tsel=0&kc=1&tk=%s&q=%s" % (tk, content) # 返回值是一個多層嵌套列表的字符串形式,解析起來還相當費勁,寫了幾個正則,發(fā)現(xiàn)也很不理想, # 后來感覺,使用正則簡直就是把簡單的事情復雜化,這里直接切片就Ok result = open_url(url) end = result.find("\",") if end > 4: print(' '+ result[4:end]) output = (' '+ result[4:end]) return str(output) ''' 識別驗證碼 ''' import os import requests from PIL import Image,ImageGrab import pytesseract from collections import Counter,OrderedDict# def downimg(url): # '''下載圖片''' # with open ('verifycodepage.jpg','wb') as f: # s = requests.Session() # response = s.get(url) # f.write(response.content) def acumulate_colors(image): '''對色彩像素進行統(tǒng)計''' img = Image.open(image) pixdata = img.load() # c = Counter() # print(pixdata) colors = {} for y in range(img.size[1]): for x in range(img.size[0]): #print(pixdata[x, y]) # c.update(pixdata[x, y]) if pixdata[x, y] in colors: colors[pixdata[x, y]] += 1 else: colors[pixdata[x, y]] = 1 colors = sorted(colors.items(),key=lambda d:d[1],reverse=True) # c = OrderedDict(c) # print (c.values()) print(colors[2][0]) return colors# def gray(): # '''灰度化''' # img = Image.open('verifycodepage.jpg') # img.convert('L').save('灰色圖.jpg') ''' convert() 是圖像實例對象的一個方法,接受一個 mode 參數(shù),用以指定一種色彩模式,mode 的取值可以是如下幾種: · 1 (1-bit pixels, black and white, stored with one pixel per byte) · L (8-bit pixels, black and white) · P (8-bit pixels, mapped to any other mode using a colour palette) · RGB (3x8-bit pixels, true colour) · RGBA (4x8-bit pixels, true colour with transparency mask) · CMYK (4x8-bit pixels, colour separation) · YCbCr (3x8-bit pixels, colour video format) · I (32-bit signed integer pixels) · F (32-bit floating point pixels) 怎么樣,夠豐富吧?其實如此之處,PIL 還有限制地支持以下幾種比較少見的色彩模式: LA (L with alpha), RGBX (true colour with padding) and RGBa ''' def binary(image): '''二值化''' img = Image.open(image) pixdata = img.load() for y in range(img.size[1]): for x in range(img.size[0]): # if pixdata[x, y] != colors[0][0]: # pixdata[x, y] = (255,255,255) # else: # pixdata[x, y] = (0,0,0) if pixdata[x, y][0] < 115: pixdata[x, y] = (0, 0, 0)# 黑色 for y in range(img.size[1]): for x in range(img.size[0]): if pixdata[x, y][1] < 90: pixdata[x, y] = (0, 0, 0) for y in range(img.size[1]): for x in range(img.size[0]): if pixdata[x, y][2] > 120: pixdata[x, y] = (255, 255, 255)# 白色 img.save('2.jpg') ''' red 必要參數(shù);Integer類型。數(shù)值范圍從 0 255,表示顏色的紅色成份。 green 必要參數(shù);Integer類型。數(shù)值范圍從 0 255,表示顏色的綠色成份。 blue 必要參數(shù);Integer類型。數(shù)值范圍從 0 255,表示顏色的藍色成份。 ''' def denoisepoint(n,opt_point=0): '''去噪點''' direction = [ [1, 1], [1, 0], [1, -1], [0, -1], [-1, -1], [-1, 0], [-1, 1], [0, 1] ] num = 0 # 操作數(shù)量 point = 0 # 噪點數(shù) img = Image.open('2.jpg') pix = img.load() # 像素值 size = img.size #圖片大小 # print(size) for y in range(size[1]): for x in range(size[0]): num += 1 if pix[x, y][0] < n: nearpoint = 0 for (a, b) in direction: if (x+a>= 0 and x+a <= size[0]-1) and (y+b>= 0 and y+b <= size[1]-1): # 如果遇到邊界外的點不處理 if pix[x + a, y + b][0] < n: nearpoint += 1 if nearpoint <= opt_point: pix[x, y] = (255, 255, 255, 255) point += 1 # 噪點數(shù) img.save('無噪點.jpg') return (num, point) def img2string(): '''圖像轉驗證碼''' img = Image.open('無噪點.jpg') pytesseract.pytesseract.tesseract_cmd= 'C:\\Program Files(x86)\\Tesseract-OCR\\tesseract' captcha = pytesseract.image_to_string(img,lang='eng') print(captcha) return captcha''' 自動發(fā)帖 ''' import requests import re from lxml import etree from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.action_chains import ActionChains from selenium.common.exceptions import NoSuchElementException import random import time import newspaper from PIL import Imagedef get_content(url,language): '''獲取正文''' content = newspaper.Article(url, language) content.download() content.parse() return contentlogin_url = "http://www.****.so/member.php?mod=logging&action=login" def login(login_url): '''模擬登陸''' headers = { "User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3026.3 Safari/537.36" } for key,value in headers.items(): webdriver.DesiredCapabilities.PHANTOMJS['phantomjs.page.customHeaders{}'.format (key)] = valueacountdictionary = { '*****':'*****', '******':'*****', '*******':'*****', } acount = random.choice(list(acountdictionary.items())) name = acount[0] password = acount[1] print(name,password) browser.get(login_url) time.sleep(3) browser.find_element_by_xpath('//input[@name="username"]').send_keys(name) browser.find_element_by_xpath('//input[@name="password"]').send_keys(password) # browser.get_screenshot_as_file('bks.png') # 截取當前網(wǎng)頁,該網(wǎng)頁有我們需要的驗證碼 # imgelement = browser.find_element_by_xpath('//*[@id="vseccode_cS"]/img') # 定位驗證碼 # location = imgelement.location # 獲取驗證碼x,y軸坐標 # size = imgelement.size # 獲取驗證碼的長寬 # rangle = (location['x']+ size['width'], # location['y']+ ize['height'], # location['x'] + size['width'], # location['y'] + size['height']) # 寫成我們需要截取的位置坐標 # img = Image.open("bks.png") # 打開截圖 # frame = img.crop(rangle) # 使用Imagecrop函數(shù),從截圖中再次截取我們需要的區(qū)域 # frame.save('驗證碼.png') # img = Image.open('驗證碼.png') # img.show() # colors = acumulate_colors('驗證碼.png') # denoisepoint(10) # binary('驗證碼.png') # denoisepoint(100) # # devide(4) # captcha = img2string() browser.find_element_by_xpath('//input[@name="seccodeverify"]').send_keys(captcha) browser.find_element_by_xpath('//button[@name="loginsubmit"]').click() for i in range(1,20): try: # browser.execute_script('window.scrollTo(0, 5)') time.sleep(1) a = browser.find_element_by_xpath('//*[@id="ntcwin"]/table/tbody/tr/td[2]/div/i') a = a.textwhile a == '抱歉,驗證碼填寫錯誤': time.sleep(4) if browser.current_url == 'http://www.bike.so/': # print(browser.current_url) # print('驗證碼正確!!') break else: print('你還有{0}嘗試機會'.format(20 - i)) i += 1 if 20-i == 0: print('對不起驗證碼錯誤次數(shù)過多!!!') time.sleep(4) browser.close() break else: print('驗證碼錯誤!!!!請重新輸入……') browser.find_element_by_xpath('// *[ @ id = "seccode_cS"] / div / table / tbody / tr / td / a').click() # browser.get_screenshot_as_file('bks.png') # 截取當前網(wǎng)頁,該網(wǎng)頁有我們 # 需要的驗證碼 # imgelement = browser.find_element_by_xpath('//*[@id="vseccode_cS"] /img') # 定位驗證碼 # location = imgelement.location # 獲取驗證碼x,y軸坐標 # size = imgelement.size # 獲取驗證碼的長寬 # rangle = (location['x'] + size['width'], # location['y'] + size['height'], # location['x'] + size['width'], # location['y'] + size['height']) # 寫成我們需要截取的位置坐標 # img = Image.open("bks.png") # 打開截圖 # frame = img.crop(rangle) # 使用Imagecrop函數(shù),從截圖中再次截取 # 我們需要的區(qū)域 # frame.save('驗證碼.png') # img = Image.open('驗證碼.png') # img.show() # colors = acumulate_colors('驗證碼.png') # denoisepoint(10) # binary('驗證碼.png') # denoisepoint(100) # # devide(4) # captcha = img2string() browser.find_element_by_xpath('//input[@name="seccodeverify"]').clear() browser.find_element_by_xpath('//input[@name="seccodeverify"]') .send_keys(captcha) browser.find_element_by_xpath('//button[@name="loginsubmit"]').click() except NoSuchElementException: print("驗證碼正確!!") break def locat_plate(): '''定位發(fā)帖板塊''' browser.execute_script('window.scrollTo(0, 100)') time.sleep(2) # 所有版塊 plates = { 'plate1':"山地車,公路車,新聞,車友交流", 'plate2':"游泳,自行車,馬拉松,鐵人三項", 'plate3': "BMX小輪車", 'plate4': "國內(nèi)業(yè)余賽事網(wǎng)友交流", 'plate5': "智能自行車原理及動態(tài)", 'plate6': "自行車旅行路線新聞百科全書", 'plate7': "騎行眼鏡", 'plate8': "騎行書籍", 'plate9': "騎行飲料", 'plate10': "國產(chǎn)著名品牌/native", 'plate11': "Giant/捷安特", 'plate12': "Merida/美利達", 'plate13': "Lapierre/法國拉皮爾", 'plate14': "Trek/崔克", 'plate15': "Shimano/禧瑪諾" } print(""" "請選擇你要發(fā)表的版塊:", 'plate1':"山地車,公路車,新聞,車友交流", 'plate2':"游泳,自行車,馬拉松,鐵人三項", 'plate3': "BMX小輪車", 'plate4': "國內(nèi)業(yè)余賽事網(wǎng)友交流", 'plate5': "智能自行車原理及動態(tài)", 'plate6': "自行車旅行路線新聞百科全書", 'plate7': "騎行眼鏡", 'plate8': "騎行書籍", 'plate9': "騎行飲料", 'plate10': "國產(chǎn)著名品牌/native", 'plate11': "Giant/捷安特", 'plate12': "Merida/美利達", 'plate13': "Lapierre/法國拉皮爾", 'plate14': "Trek/崔克", 'plate15': "Shimano/禧瑪諾" """ ) browser.execute_script('window.scrollTo(100, 0.5*document.body.scrollHeight)') time.sleep(1) ratio = input('要重新定位到哪里?范圍是0~0.5') browser.execute_script('window.scrollTo(0.5*document.body.scrollHeight, {}*document.body. scrollHeight)'.format(ratio)) plate = input('請輸入你要發(fā)帖的版塊:') browser.find_element_by_link_text(plates[plate]).click() time.sleep(2) def random_pick(some_list, probabilities): '''定義不等概率抽樣''' x = random.uniform(0, 1) cumulative_probability = 0.0 for item, item_probability in zip(some_list, probabilities): cumulative_probability += item_probabilityif x < cumulative_probability: break return itemdef post_content(content): '''自動發(fā)帖''' browser.find_element_by_id('newspecial').click() browser.switch_to.frame("e_iframe") browser.find_element_by_xpath('/html/body').send_keys(Keys.TAB) a = content.text.split('\n') postcontent = [] for i in a: if i != '': output = translate(i) + '\n' postcontent.append(output) else: beautystyle = [i, '……………………………………………………………………………………………………………………………………………', '=====================================================', '-----------------------------------------------------', '—————————————————————————————————————————————————————' ] probabilities = [0.8, 0.05, 0.05, 0.05, 0.05] line = random_pick(beautystyle, probabilities) postcontent.append(line + '\n') browser.find_element_by_xpath('/html/body').send_keys(postcontent) time.sleep(4) browser.switch_to.default_content() # 或者driver.switch_to.parent_frame() if content.title != '': # if flag == 0: title = translate(content.title) browser.find_element_by_xpath('//*[@id="subject"]').send_keys(title) else: browser.find_element_by_xpath('//*[@id="subject"]').send_keys(input('請輸入標題:')) browser.execute_script('window.scrollTo(0, 300)') time.sleep(2) # browser.find_element_by_xpath('//button[@id="為了不給網(wǎng)站帶來麻煩, 請大家不要使用此命令"]').click() # 編輯帖子 # browser.find_element_by_link_text('編輯').click() # browser.page_source if __name__ == '__main__': # 獲取正文并翻譯 urls = [ 'http://www.360doc.com/content/11/1021/10/7796166_157906146.shtml', ] for url in urls: # 登錄論壇 browser = webdriver.Chrome() browser.maximize_window() login(login_url) content = get_content(url,'en') # 定位發(fā)帖版塊 locat_plate() # 發(fā)帖 post_content(content) # browser.close()

總結

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

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

主站蜘蛛池模板: 精品动漫3d一区二区三区免费版 | 男女超爽视频免费播放 | 日韩和的一区二区 | 国产精品探花在线观看 | 午夜精品久久 | 天堂а√在线中文在线鲁大师 | 国产精品最新 | 久久久久久久久久福利 | 欧美日韩中文国产一区发布 | 少妇h视频| 亚洲欧美不卡 | 国产欧美一区二区精品性色99 | 久久亚洲精华国产精华液 | 午夜电影在线播放 | 求av网站| 美女被娇喘视频 | av一本在线 | 日本少妇xxxx | 爱爱免费网站 | 国产swag在线| 91精品国产电影 | 日本一级一片免费视频 | 国产视频第三页 | 精品不卡一区二区三区 | 欧美香蕉网 | 欧美一级电影在线 | 中文字幕在线高清 | 高潮爽爆喷水h | 国产成人精品在线观看 | 日韩免费影院 | 欧美成人三级伦在线观看 | 国产精品色综合 | 骚色综合 | 亚洲精品国产一区二区 | 精品无码一区二区三区蜜臀 | 玩偶姐姐在线观看免费 | 人人人人干 | 下面一进一出好爽视频 | 久久亚洲精华国产精华液 | 免费伊人| 屁股夹体温计调教play | 四虎影视精品 | 蜜桃视频无码区在线观看 | 色视频在线看 | av色先锋 | 富二代成人短视频 | 久久午夜视频 | 欧美黄色片免费看 | 免费日韩在线 | 中文字幕无码人妻少妇免费 | 成人影视网址 | 三级久久| 天堂色综合 | 天天干天天爱天天射 | 黄色片视频网站 | 日本天堂影院 | 西野翔夫の目の前で犯在线 | 国产精品正在播放 | 九九综合网 | 日韩精品一区二 | 亚洲综合一区二区三区 | 香蕉国产在线观看 | 三级三级久久三级久久 | 亚洲黄色成人 | 91传媒在线播放 | 艳母日本动漫在线观看 | 蜜桃一二三区 | 色午夜| 精品偷拍网 | 国产精品3 | 三年大全国语中文版免费播放 | 黄色国产免费 | 精品人妻少妇一区二区三区 | 久久东京 | 欧美成人性生活 | 99视频精品 | 国产精品毛片久久 | 欧美不卡高清 | 免费网站黄色 | 人妻少妇精品一区二区三区 | 色秀视频在线观看 | 少妇中文字幕 | 久久久久久久久久久97 | 伊人三区| 无码少妇一区二区三区芒果 | 上原亚衣在线 | av女人的天堂 | 成人午夜免费网站 | 欧美激情成人在线 | 永久免费视频网站 | 一个人看的毛片 | 国产亚洲精品久久久久久无几年桃 | 国产网红主播精品av | 国产成人一级 | 69福利社区 | 三年中文在线观看免费观看 | 中文字幕黄色片 | 这里只有精品免费视频 | 最新黄色网址在线观看 |