Python 通過打碼平臺實現(xiàn)驗證碼的實現(xiàn)
在爬蟲時,經常遇到登錄需要驗證碼的情況,簡單的驗證碼可以自己解決,復制的驗證碼需要借助機器學習,有一定的難度。還有一個簡單的方案就是采用付費的打碼平臺。
比如R若快(http://www.ruokuai.com/client),還有云打碼平臺(http://www.yundama.com/price.html)
下面以R若快為例介紹打碼平臺的思路:
R若快平臺需要注冊兩個用戶,一個是普通用戶,一個開發(fā)者用戶,




1、首先驗證碼截圖,就是截取網站上登錄頁面的驗證碼圖片并保存到本地
2、調用打碼平臺的接口把驗證碼圖片發(fā)送到打碼平臺并獲取到驗證碼結果。
具體代碼如下:
#!/usr/bin/env python
# coding:utf-8
import requests
from hashlib import md5
class RClient(object):
def __init__(self, username='shaoks123', password='123456', soft_id='113452', soft_key='c0d07d796c8e470c92a126df60d61794'):
self.username = username
# self.password = md5(password).hexdigest()
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.jpg', 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 test(self,imagefile,im_type=1030):
# im = open('E:\python36_crawl\Veriycode\code\code_823.png', 'rb').read()
im = open(imagefile, 'rb').read()
result = self.rk_create(im, im_type)
print(result['Result'])
return result['Result']
# if __name__ == '__main__':
# rc = RClient()
# im = open('E:\python36_crawl\Veriycode\code\code_823.png', 'rb').read()
# result = rc.rk_create(im, 1030)
# print(result['Result'])
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
Python利用Rasa框架和SMTPlib庫實現(xiàn)郵件回復助手
在現(xiàn)代辦公場景中,處理大量郵件是一項既耗時又容易出錯的任務,本文將詳細介紹如何使用Python的Rasa框架和SMTPlib庫建一個智能的郵件自動回復助手,感興趣的可以了解下2025-04-04
Python?中?threading.Thread.join()?的使用方法示例詳解
threading.Thread.join()用于阻塞當前線程,直到調用它的線程對象執(zhí)行完成或者超時,在Python中,想要充分利用多線程的優(yōu)勢,就需要對threading模塊中的 Thread 類了解,這里有一個非常簡單的多線程程序,幫助理解 threading.Thread.join 方法,感興趣的朋友跟隨小編一起看看吧2024-06-06
python函數(shù)參數(shù),名稱空間,以及函數(shù)嵌套
這篇文章主要給大家介紹python函數(shù)參數(shù)、名稱空間、以及函數(shù)嵌套的相關資料,想具體了解的小伙伴請和小編一起進入下面文章內容吧2021-10-10

