利用打碼兔和超人打碼自封裝的打碼類分享
自封裝的打碼類, windows下建議用打碼兔(調(diào)用的官方dll),linux下建議超人打碼(http api)
# coding:utf-8
from ctypes import *
import requests
import json
import random
import binascii
from config import config
class Dama2():
"""打碼兔打碼."""
_username = ''
_password = ''
__attrs__ = ['DM', 'username', 'password', 'softuuid', 'timeout']
def __init__(self):
self.DM = WinDLL('lib/CrackCaptchaAPI.dll')
if not self._username:
Dama2._username = config['dama']['dama2']['username']
Dama2._password = config['dama']['dama2']['password']
self.username = c_char_p(self._username)
self.password = c_char_p(self._password)
self.softuuid = c_char_p('6fbc06efdc777eee854842572102daec')
self.timeout = c_ushort(30)
def recv_byte(self, imgdata, imgtype=42):
# imgdata = c_void_p(imgdata)
imgleng = c_uint(len(imgdata))
imgtype = c_ulong(imgtype)
res = c_char_p('')
code = self.DM.D2Buf(self.softuuid, self.username, self.password, imgdata, imgleng, self.timeout, imgtype, res)
if code > 0:
return res.value
return False
def report_err(self, imgid):
return False
class Chaoren():
_username = ''
_password = ''
__attrs__ = ['DM', 'username', 'password', 'softuuid', 'timeout']
def __init__(self):
if not self._username:
Chaoren._username = config['dama']['chaoren']['username']
Chaoren._password = config['dama']['chaoren']['password']
self.s = requests.Session()
self.s.encoding = 'utf-8'
self.s.timeout = 16
self.data = {
'username': self.username,
'password': self.password,
'softid': '1234',#1234換成自己的
'imgid': '',
'imgdata': ''
}
def get_left_point(self):
try:
r = self.s.post('http://apib.sz789.net:88/GetUserInfo.ashx', self.data)
return r.json()
except requests.ConnectionError:
return self.get_left_point()
except:
return False
def recv_byte(self, imgdata):
self.data['imgdata'] = binascii.b2a_hex(imgdata).upper()
try:
r = self.s.post('http://apib.sz789.net:88/RecvByte.ashx', self.data)
res = r.json()
if res[u'info'] == -1:
self.report_err(res[u'imgid']) # 識別錯誤
return False
return r.json()[u'result']
except requests.ConnectionError:
return self.recv_byte(imgdata)
except:
return False
def report_err(self, imgid):
self.data['imgid'] = imgid
if self.data['imgdata']:
del self.data['imgdata']
try:
r = self.s.post('http://apib.sz789.net:88/ReportError.ashx', self.data)
return r.json()
except requests.ConnectionError:
return self.report_err(imgid)
except:
return False
class Dama():
flag = 'dama2'
def __init__(self):
if self.flag == 'dama2':
self.w = Dama2()
elif self.flag == 'chaoren':
self.w = Chaoren()
else:
self.w = Dama2() # 默認(rèn)
def recv_byte(self, imgdata):
return self.w.recv_byte(imgdata)
def report_err(self, imgid):
return self.w.report_err(imgid)
# test
if __name__ == '__main__':
pass
"""
username and password 更換為自己的
"""
相關(guān)文章
pytho matplotlib工具欄源碼探析一之禁用工具欄、默認(rèn)工具欄和工具欄管理器三種模式的差異
這篇文章主要介紹了pytho matplotlib工具欄源碼探析一之禁用工具欄、默認(rèn)工具欄和工具欄管理器三種模式的差異,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-02-02實例講解Python中函數(shù)的調(diào)用與定義
這篇文章主要介紹了Python中函數(shù)的調(diào)用與定義,是Python入門學(xué)習(xí)中的基礎(chǔ)知識,需要的朋友可以參考下2016-03-03python pandas 解析(讀取、寫入)CSV 文件的操作方法
這篇文章主要介紹了python pandas 解析(讀取、寫入) CSV 文件,本文通過示例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-12-12Pytorch訓(xùn)練網(wǎng)絡(luò)過程中l(wèi)oss突然變?yōu)?的解決方案
這篇文章主要介紹了Pytorch訓(xùn)練網(wǎng)絡(luò)過程中l(wèi)oss突然變?yōu)?的解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-05-05Pycharm 文件更改目錄后,執(zhí)行路徑未更新的解決方法
今天小編就為大家分享一篇Pycharm 文件更改目錄后,執(zhí)行路徑未更新的解決方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-07-07python備份文件以及mysql數(shù)據(jù)庫的腳本代碼
最近正在學(xué)習(xí)python,看了幾天了,,所以寫個小腳本練習(xí)練習(xí),沒什么含金量,只當(dāng)練手2013-06-06