欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python圖片驗(yàn)證碼識(shí)別最新模塊muggle_ocr的示例代碼

 更新時(shí)間:2020年07月03日 08:48:28   作者:小小咸魚YwY  
這篇文章主要介紹了python圖片驗(yàn)證碼識(shí)別最新模塊muggle_ocr的相關(guān)知識(shí),本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

一.官方文檔

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

二模塊安裝

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

三.使用代碼

# 導(dǎo)入包
import muggle_ocr

# 初始化;model_type 包含了 ModelType.OCR/ModelType.Captcha 兩種
sdk = muggle_ocr.SDK(model_type=muggle_ocr.ModelType.OCR)
# ModelType.OCR 可識(shí)別光學(xué)印刷文本 這里個(gè)人覺得應(yīng)該是官方文檔寫錯(cuò)了 官方文檔是ModelType.Captcha 可識(shí)別光學(xué)印刷文本
with open(r"test1.png", "rb") as f:
 b = f.read()
text = sdk.predict(image_bytes=b)
print(text)

# ModelType.Captcha 可識(shí)別4-6位驗(yàn)證碼
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 實(shí)現(xiàn)全自動(dòng)登錄(真正的全自動(dòng),自動(dòng)識(shí)別驗(yàn)證碼)

你沒有看錯(cuò),全自動(dòng)驗(yàn)證~~~

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

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

  • selenium (本意是用來全自動(dòng)測(cè)試)
  • Phantomjs (一種沒有界面的瀏覽器)
  • ** 驗(yàn)證碼識(shí)別器(一塊錢可用100次的這種)

關(guān)門放代碼

from selenium import webdriver
from PIL import Image
if __name__ == '__main__':
 wbe = webdriver.PhantomJS()
 wbe.get("https://www.某個(gè)網(wǎng)站的登錄頁面.com/login/index.html")//你可以拿知乎,百度,等等測(cè)試
 element = wbe.find_element_by_xpath('//*[@id="entry_name"]/p[3]/img')//驗(yàn)證碼所在的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('驗(yàn)證碼.png')
#!/usr/bin/env python
# coding:utf-8
import requests
from hashlib import md5
class 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: 圖片字節(jié)
  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:報(bào)錯(cuò)題目的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')//想拿下測(cè)試的留言我,教你拿到測(cè)試賬號(hào)
 im = open('a.png', 'rb').read()
 print rc.rk_create(im, 3040)

完整代碼

#!/usr/bin/env python
# coding:utf-8
from selenium import webdriver
from PIL import Image
import requests
from hashlib import md5
import time
class 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: 圖片字節(jié)
  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:報(bào)錯(cuò)題目的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('賬號(hào)', '密碼', '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")

總結(jié)

到此這篇關(guān)于python圖片驗(yàn)證碼識(shí)別最新模塊muggle_ocr的示例代碼的文章就介紹到這了,更多相關(guān)python 驗(yàn)證碼識(shí)別模塊muggle_ocr內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 如何在Python 游戲中模擬引力

    如何在Python 游戲中模擬引力

    這篇文章主要介紹了在你的 Python 游戲中模擬引力的操作方法,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-03-03
  • Python 刪除整個(gè)文本中的空格,并實(shí)現(xiàn)按行顯示

    Python 刪除整個(gè)文本中的空格,并實(shí)現(xiàn)按行顯示

    今天小編就為大家分享一篇Python 刪除整個(gè)文本中的空格,并實(shí)現(xiàn)按行顯示,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2018-07-07
  • python中reader的next用法

    python中reader的next用法

    這篇文章主要介紹了python中reader的next用法,分別介紹了python3中的用法和python2中的用法,具體實(shí)例代碼大家參考下本文
    2018-07-07
  • Python使用__new__()方法為對(duì)象分配內(nèi)存及返回對(duì)象的引用示例

    Python使用__new__()方法為對(duì)象分配內(nèi)存及返回對(duì)象的引用示例

    這篇文章主要介紹了Python使用__new__()方法為對(duì)象分配內(nèi)存及返回對(duì)象的引用,結(jié)合實(shí)例形式分析了Python對(duì)象初始化及內(nèi)存操作相關(guān)使用技巧,需要的朋友可以參考下
    2019-09-09
  • Python實(shí)現(xiàn)簡(jiǎn)單的索引排序與搜索功能

    Python實(shí)現(xiàn)簡(jiǎn)單的索引排序與搜索功能

    這篇文章主要介紹了Python實(shí)現(xiàn)簡(jiǎn)單的索引排序與搜索功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-04-04
  • numpy中的converters和usecols用法詳解

    numpy中的converters和usecols用法詳解

    本文主要介紹了numpy中的converters和usecols用法詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-05-05
  • Python編程實(shí)戰(zhàn)之Oracle數(shù)據(jù)庫操作示例

    Python編程實(shí)戰(zhàn)之Oracle數(shù)據(jù)庫操作示例

    這篇文章主要介紹了Python編程實(shí)戰(zhàn)之Oracle數(shù)據(jù)庫操作,結(jié)合具體實(shí)例形式分析了Python的Oracle數(shù)據(jù)庫模塊cx_Oracle包安裝、Oracle連接及操作技巧,需要的朋友可以參考下
    2017-06-06
  • Python利用PyMuPDF模塊實(shí)現(xiàn)快速轉(zhuǎn)換PDF文件

    Python利用PyMuPDF模塊實(shí)現(xiàn)快速轉(zhuǎn)換PDF文件

    PDF是一種廣泛使用的文件格式,可以在任何設(shè)備上查看和打印,那么如何用Python和PyMuPDF制作你想要大小的PDF文件呢,本文就來和大家詳細(xì)講講
    2023-08-08
  • numpy中數(shù)組的堆疊方法

    numpy中數(shù)組的堆疊方法

    本文主要介紹了numpy中數(shù)組的堆疊方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-02-02
  • Python如何統(tǒng)計(jì)大小寫字母?jìng)€(gè)數(shù)和數(shù)字個(gè)數(shù)

    Python如何統(tǒng)計(jì)大小寫字母?jìng)€(gè)數(shù)和數(shù)字個(gè)數(shù)

    這篇文章主要介紹了Python如何統(tǒng)計(jì)大小寫字母?jìng)€(gè)數(shù)和數(shù)字個(gè)數(shù)問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-08-08

最新評(píng)論