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

Python爬蟲之超級鷹驗證碼應用

 更新時間:2022年08月19日 10:01:55   作者:XWenXiang  
眾所周知python是一個很強大的語言,它擁有眾多的庫,今天我嘗試了使用超級鷹第三方平臺進行驗證碼的開發(fā),需要的朋友可以參考下

超級鷹平臺

驗證碼的破解可以有以下方式:

  • 簡單的數(shù)字字母組合可以使用圖像識別(python 現(xiàn)成模塊),成功率不高
  • 使用第三方打碼平臺(破解驗證碼平臺),花錢,把驗證碼圖片給它,返回識別完的結果

第三方平臺有超級鷹等等。

基礎使用

在其官網(wǎng)注冊賬號后,綁定微信會提供免費的1000題分,可用于驗證碼識別

創(chuàng)建開發(fā)者賬號,并且注冊一個軟件

下載 python demo

基礎使用

下載的demo是使用python2編寫的,需要簡單修改

import requests
from hashlib import md5
class ChaojiyingClient(object):
    def __init__(self, username, password, soft_id):
        self.username = username
        password = password.encode('utf8')
        self.password = md5(password).hexdigest()
        self.soft_id = soft_id
        self.base_params = {
            'user': self.username,
            'pass2': self.password,
            'softid': self.soft_id,
        }
        self.headers = {
            'Connection': 'Keep-Alive',
            'User-Agent': 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)',
        }
    def PostPic(self, im, codetype):
        """
        im: 圖片字節(jié)
        codetype: 題目類型 參考 http://www.chaojiying.com/price.html
        """
        params = {
            'codetype': codetype,
        }
        params.update(self.base_params)
        files = {'userfile': ('ccc.jpg', im)}
        r = requests.post('http://upload.chaojiying.net/Upload/Processing.php', data=params, files=files,
                          headers=self.headers)
        return r.json()
    def PostPic_base64(self, base64_str, codetype):
        """
        im: 圖片字節(jié)
        codetype: 題目類型 參考 http://www.chaojiying.com/price.html
        """
        params = {
            'codetype': codetype,
            'file_base64': base64_str
        }
        params.update(self.base_params)
        r = requests.post('http://upload.chaojiying.net/Upload/Processing.php', data=params, headers=self.headers)
        return r.json()
    def ReportError(self, im_id):
        """
        im_id:報錯題目的圖片ID
        """
        params = {
            'id': im_id,
        }
        params.update(self.base_params)
        r = requests.post('http://upload.chaojiying.net/Upload/ReportError.php', data=params, headers=self.headers)
        return r.json()
if __name__ == '__main__':
    chaojiying = ChaojiyingClient('超級鷹用戶名', '超級鷹用戶名的密碼', '96001')  # 用戶中心>>軟件ID 生成一個替換 96001
    im = open('a.jpg', 'rb').read()  # 本地圖片文件路徑 來替換 a.jpg 有時WIN系統(tǒng)須要//
    print(chaojiying.PostPic(im, 1902))  # 1902 驗證碼類型  官方網(wǎng)站>>價格體系 3.4+版 print 后要加()
    # print chaojiying.PostPic(base64_str, 1902)  #此處為傳入 base64代碼

剪切驗證碼

實際使用的時候驗證碼是不固定的,需要剪切下來使用,需要使用 pillow 模塊

截圖需要注意分辨率

from selenium import webdriver
from selenium.webdriver.common.by import By
from PIL import Image
from selenium.webdriver.chrome.options import Options
from chaojiying import chaojiying_Python
chrome_options = Options()
chrome_options.add_argument('window-size=1920x1080')  # 指定瀏覽器分辨率
chrome_options.add_argument('--disable-gpu')  # 谷歌文檔提到需要加上這個屬性來規(guī)避bug
chrome_options.add_argument('--hide-scrollbars')  # 隱藏滾動條, 應對一些特殊頁面
# chrome_options.add_argument('blink-settings=imagesEnabled=false')  # 不加載圖片, 提升速度
chrome_options.add_argument('--headless')  # 瀏覽器不提供可視化頁面. linux下如果系統(tǒng)不支持可視化不加這條會啟動失敗
# chrome = webdriver.Chrome(executable_path='../chromedriver.exe')
chrome = webdriver.Chrome(executable_path='../chromedriver.exe', options=chrome_options)
chrome.implicitly_wait(10)
chrome.maximize_window()
try:
    chrome.get('http://www.aa7a.cn/user.php?')
    username = chrome.find_element(By.ID, 'username')
    password = chrome.find_element(By.ID, 'password')
    captcha = chrome.find_element(By.ID, 'captcha')
    # 保存大圖
    chrome.save_screenshot('main.png')
    img = chrome.find_element(By.ID, 'login_img_checkcode')
    img_location = img.location
    img_size = img.size
    # 使用pillow扣除大圖中的驗證碼
    img_tu = (
        int(img_location['x']),
        int(img_location['y']),
        int(img_location['x'] + img_size['width']),
        int(img_location['y'] + img_size['height']),
    )
    # 打開頁面大圖
    im = Image.open('./main.png')
    # 剪切驗證碼圖片
    fram = im.crop(img_tu)
    # 保存驗證碼圖片
    fram.save('code.png')
    # 打開驗證碼圖片
    code_img = open('code.png', 'rb').read()
    # 調(diào)用超級鷹識別
    res = chaojiying_Python.chaojiying.PostPic(code_img, 1902)
    code = res.get('pic_str')
    username.send_keys('username')
    password.send_keys('123')
    captcha.send_keys(code)
    print(code)
except Exception as e:
    print(e)
finally:
    chrome.quit()

到此這篇關于Python爬蟲之超級鷹驗證碼應用的文章就介紹到這了,更多相關Python驗證碼內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

  • python實現(xiàn)從ftp服務器下載文件

    python實現(xiàn)從ftp服務器下載文件

    這篇文章主要為大家詳細介紹了python實現(xiàn)從ftp服務器下載文件,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-03-03
  • Python實現(xiàn)遍歷windows所有窗口并輸出窗口標題的方法

    Python實現(xiàn)遍歷windows所有窗口并輸出窗口標題的方法

    這篇文章主要介紹了Python實現(xiàn)遍歷windows所有窗口并輸出窗口標題的方法,涉及Python調(diào)用及遍歷windows窗口句柄的技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-03-03
  • Pycharm?cannot?set?up?a?python?SDK問題的原因及解決方法

    Pycharm?cannot?set?up?a?python?SDK問題的原因及解決方法

    這篇文章主要給大家介紹了關于Pycharm?cannot?set?up?a?python?SDK問題的原因及解決方法,這個問題已經(jīng)不是第一次出現(xiàn)了,所以干脆總結下,需要的朋友可以參考下
    2022-06-06
  • 解決python彩色螺旋線繪制引發(fā)的問題

    解決python彩色螺旋線繪制引發(fā)的問題

    今天小編就為大家分享一篇解決python彩色螺旋線繪制引發(fā)的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-11-11
  • Python制作詞云的方法

    Python制作詞云的方法

    這篇文章主要為大家詳細介紹了Python制作詞云的方法,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-01-01
  • 通過Python pyecharts輸出保存圖片代碼實例

    通過Python pyecharts輸出保存圖片代碼實例

    這篇文章主要介紹了通過Python pyecharts輸出保存圖片代碼實例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-11-11
  • Python+Tkinter制作猜燈謎小游戲

    Python+Tkinter制作猜燈謎小游戲

    元宵節(jié),又稱上元節(jié)、燈節(jié),是春節(jié)之后的第一個重要節(jié)日。而元宵節(jié)除了吃元宵、看花燈,還有一件最重要的事情就是猜燈謎!因此本文將通過Python Tkinter制作一個猜燈謎小游戲,感興趣的小伙伴可以了解一下
    2022-02-02
  • Python中Permission denied的解決方案

    Python中Permission denied的解決方案

    這篇文章主要介紹了Python中Permission denied的解決方案,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-04-04
  • python裝飾器初探(推薦)

    python裝飾器初探(推薦)

    下面小編就為大家?guī)硪黄猵ython裝飾器初探(推薦)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2016-07-07
  • Python數(shù)字圖像處理基礎直方圖詳解

    Python數(shù)字圖像處理基礎直方圖詳解

    這篇文章主要介紹了Python數(shù)字圖像處理基礎直方圖詳解,本文對Python直方圖的定義、性質(zhì)、應用以及Python直方圖的計算作了詳細的講解,有需要朋友可以借鑒參考下
    2021-09-09

最新評論