python图片验证码解决方案

验证码:图片验证码、特殊验证码、语音验证码
https://www.showapi.com/apiGateway/view/932

import pytesseract
from PIL import Image
from ShowapiRequest.ShowapiRequest import ShowapiRequest

图片验证码方案一:

image = Image.open(“C:/Users/Administrator/Desktop/s.png”)
text = pytesseract.image_to_string(image)
print(text)

图片验证码方案二:

r=ShowapiRequest(“http://route.showapi.com/2360-2?showapi_appid=737817&showapi_sign=3f4deeddd98c44c1bfad0bd3869f8491”,my_appId=737817,my_appSecret=‘3f4deeddd98c44c1bfad0bd3869f8491’)
r.addBodyPara(“file_base64”, “要解析的验证码图片base64位解码后的值”)
res = r.post()
print(res.json()[‘showapi_res_body’][‘pic_str’])

ShowapiRequest.py文件
import requests
from urllib import parse
#全局请求头
files = {}
headers = {}
body = {}
timeouts = {}
resHeader = {}

class ShowapiRequest:
def init(self, url, my_appId, my_appSecret):
self.url = url
self.my_appId = my_appId
self.my_appSecret = my_appSecret
body[“showapi_appid”] = my_appId
body[“showapi_sign”] = my_appSecret
headers[“User-Agent”] = “Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2427.7 Safari/537.36”

def addFilePara(self, key, value_url):
    files[key] = open(r"%s" % (value_url), 'rb')
    return self

def addHeadPara(self, key, value):
    headers[key] = value
    return self

def addBodyPara(self, key, value):
    body[key] = value
    return self
#设置连接时间和读取时间
def setTimeout(self, connecttimout, readtimeout):
    timeouts["connecttimout"] = connecttimout
    timeouts["readtimeout"] = readtimeout
    return self


def get(self):
    get_url = self.url + "?" + parse.urlencode(body)
    if not timeouts:
        res = requests.get(get_url, headers=headers)
    else:
        timeout = (timeouts["connecttimout"], timeouts["readtimeout"])
        res = requests.get(get_url, headers=headers, timeout=timeouts)
    return res

def post(self):
    if not timeouts:
        res = requests.post(self.url, files=files, data=body, headers=headers)
    else:
        timeout = (timeouts["connecttimout"], timeouts["readtimeout"])
        res = requests.post(self.url, files=files, data=body, headers=headers, timeout=timeout)
    return res
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值