色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁技術文章
文章詳情頁

python圖片驗證碼識別最新模塊muggle_ocr的示例代碼

瀏覽:3日期:2022-07-18 17:56:09

一.官方文檔

https://pypi.org/project/muggle-ocr/

二模塊安裝

pip install muggle-ocr# 因模塊過新,阿里/清華等第三方源可能尚未更新鏡像,因此手動指定使用境外源,為了提高依賴的安裝速度,可預先自行安裝依賴:tensorflow/numpy/opencv-python/pillow/pyyaml

三.使用代碼

# 導入包import muggle_ocr# 初始化;model_type 包含了 ModelType.OCR/ModelType.Captcha 兩種sdk = muggle_ocr.SDK(model_type=muggle_ocr.ModelType.OCR)# ModelType.OCR 可識別光學印刷文本 這里個人覺得應該是官方文檔寫錯了 官方文檔是ModelType.Captcha 可識別光學印刷文本with open(r'test1.png', 'rb') as f: b = f.read()text = sdk.predict(image_bytes=b)print(text)# ModelType.Captcha 可識別4-6位驗證碼sdk = muggle_ocr.SDK(model_type=muggle_ocr.ModelType.Captcha)with open(r'test1.png', 'rb') as f: b = f.read()text = sdk.predict(image_bytes=b)print(text)

PS:下面看下 Python 實現全自動登錄(真正的全自動,自動識別驗證碼)

你沒有看錯,全自動驗證~~~

黑科技?還是黑代碼?我感覺這個看在你用啥,對不對?反正我用來(* * * * ) 你懂得

好了,先說一下用到的東西

selenium (本意是用來全自動測試) Phantomjs (一種沒有界面的瀏覽器) ** 驗證碼識別器(一塊錢可用100次的這種)

關門放代碼

from selenium import webdriverfrom PIL import Imageif __name__ == ’__main__’: wbe = webdriver.PhantomJS() wbe.get('https://www.某個網站的登錄頁面.com/login/index.html')//你可以拿知乎,百度,等等測試 element = wbe.find_element_by_xpath(’//*[@id='entry_name']/p[3]/img’)//驗證碼所在的xpath路徑 left = element.location[’x’] top = element.location[’y’] right = element.location[’x’] + element.size[’width’] bottom = element.location[’y’] + element.size[’height’] im = Image.open(r’登錄頁.png’)//全頁面截屏 im = im.crop((left, top, right, bottom)) im.save(’驗證碼.png’)

#!/usr/bin/env python# coding:utf-8import requestsfrom hashlib import md5class RClient(object): def __init__(self, username, password, soft_id, soft_key): self.username = username self.password = md5(password).hexdigest() self.soft_id = soft_id self.soft_key = soft_key self.base_params = { ’username’: self.username, ’password’: self.password, ’softid’: self.soft_id, ’softkey’: self.soft_key, } self.headers = { ’Connection’: ’Keep-Alive’, ’Expect’: ’100-continue’, ’User-Agent’: ’ben’, } def rk_create(self, im, im_type, timeout=60): ''' im: 圖片字節 im_type: 題目類型 ''' params = { ’typeid’: im_type, ’timeout’: timeout, } params.update(self.base_params) files = {’image’: (’a.png’, im)} r = requests.post(’http://api.ruokuai.com/create.json’, data=params, files=files, headers=self.headers) return r.json() def rk_report_error(self, im_id): ''' im_id:報錯題目的ID ''' params = { ’id’: im_id, } params.update(self.base_params) r = requests.post(’http://api.ruokuai.com/reporterror.json’, data=params, headers=self.headers) return r.json()def get_code(): rc = RClient(’用戶名’, ’密碼’, ’94522’, ’62c235939b7240879453f31603733fd6’)//想拿下測試的留言我,教你拿到測試賬號 im = open(’a.png’, ’rb’).read() print rc.rk_create(im, 3040)

完整代碼

#!/usr/bin/env python# coding:utf-8from selenium import webdriverfrom PIL import Imageimport requestsfrom hashlib import md5import timeclass RClient(object): def __init__(self, username, password, soft_id, soft_key): self.username = username self.password = md5(password.encode('utf-8')).hexdigest() self.soft_id = soft_id self.soft_key = soft_key self.base_params = { ’username’: self.username, ’password’: self.password, ’softid’: self.soft_id, ’softkey’: self.soft_key, } self.headers = { ’Connection’: ’Keep-Alive’, ’Expect’: ’100-continue’, ’User-Agent’: ’ben’, } def rk_create(self, im, im_type, timeout=60): ''' im: 圖片字節 im_type: 題目類型 ''' params = { ’typeid’: im_type, ’timeout’: timeout, } params.update(self.base_params) files = {’image’: (’a.png’, im)} r = requests.post(’http://api.ruokuai.com/create.json’, data=params, files=files, headers=self.headers) return r.json() def rk_report_error(self, im_id): ''' im_id:報錯題目的ID ''' params = { ’id’: im_id, } params.update(self.base_params) r = requests.post(’http://api.ruokuai.com/reporterror.json’, data=params, headers=self.headers) return r.json()def get_code(im_file): rc = RClient(’賬號’, ’密碼’, ’94522’, ’62c235939b7240879453f31603733fd6’) im_source = open(im_file, 'rb').read() print(rc.rk_create(im_source, 3040))if __name__ == ’__main__’: wbe = webdriver.PhantomJS() wbe.get('https://www.dajiang365.com/login/index.html') time.sleep(2) wbe.save_screenshot('das.png') element = wbe.find_element_by_xpath(’//*[@id='entry_name']/p[3]/img’) left = element.location[’x’] top = element.location[’y’] right = element.location[’x’] + element.size[’width’] bottom = element.location[’y’] + element.size[’height’] im = Image.open(r’das.png’) im = im.crop((left, top, right, bottom)) im.save(’a.png’) time.sleep(2) get_code('a.png')

總結

到此這篇關于python圖片驗證碼識別最新模塊muggle_ocr的示例代碼的文章就介紹到這了,更多相關python 驗證碼識別模塊muggle_ocr內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 91精品国产91久久久久久青草 | 国产美女作爱 | 国产精品亚洲二线在线播放 | 步兵精品手机在线观看 | 一区二区三区视频在线 | 国产在线观看精品 | 精品视频一区二区 | 日本午夜vr影院新入口 | 日韩 亚洲 制服 欧美 综合 | 中文字幕一区二区三区精彩视频 | 亚洲精品高清在线观看 | 久久久99精品免费观看精品 | 国产自线一二三四2021 | 国产欧美成人不卡视频 | 黄网站免费在线 | 另类亚洲孕妇分娩网址 | caoporen在线视频入口 | 草草视频在线播放 | 欧美大片aaa | 韩国毛片基地 | 久草在线青青草 | 国产精品2020 | 热er99久久6国产精品免费 | 国产超薄肉色丝袜足j | 国产国语高清在线视频二区 | 国产成人午夜精品免费视频 | 国产精品毛片在线大全 | 夜精品a一区二区三区 | 国产黄色自拍视频 | 高清国产在线播放成人 | 国产三级一区二区 | 亚洲第一区精品日韩在线播放 | 亚洲欧美国产精品专区久久 | 日韩欧美特级毛片 | 欧美国产永久免费看片 | 黄色大片三级 | 一级a毛片| 日本wwwwwwwww | 美女很黄很黄免费的 | 国产精品久久亚洲一区二区 | 午夜两性试爱视频免费 |