验证码 识别

复制代码
#!/usr/bin/env python
# encoding: utf-8

#@author: 东哥加油
#@file: autologin.py
#@time: 2018/12/19 10:14

import requests
import json
import jsonpath
import base64
import pytesseract
import re

from PIL import Image

class autologin:
    def __init__(self):
        print('')

    def login(self,quanshang):
        if quanshang == '10gcw':
            self.login_dfcf()
        else:
            print('接口未开发')

    def login_dfcf(self):
        sess = requests.session()
        headers = {
            'Origin':'http://www.10gcw.com',
            'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36',
            'Origin':'http://www.10gcw.com',
            'Referer': 'http://www.10gcw.com/reg',
            'Accept': 'application/json, text/plain, */*',
        }
        url_yzm = 'http://api.99bccp.com/member/v1/code'
        response = sess.get(url_yzm,headers=headers)
        html = response.text
        jsonobj = json.loads(html)
        clientId = jsonpath.jsonpath(jsonobj, '$..clientId')
        code = jsonpath.jsonpath(jsonobj, '$..code')
        img = base64.b64decode(code[0])
        file = open('yzm.png', 'wb')
        file.write(img)
        file.close()

        image = Image.open('yzm.png')
        img = image.convert("RGBA")
        str = pytesseract.image_to_string(img)
        nstr = re.findall('\d+', str)
        str_1 = ''
        for i in nstr:
            str_1 = str_1 + i

        d_yzm = int(str_1)
        print(d_yzm)

        url = 'http://api.99bccp.com/member/v1/register/login'
        headers = {
            'Origin':'http://www.10gcw.com',
            'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36',
            'clientId':clientId[0],
            'Referer':'http://www.10gcw.com/reg',
            'Accept':'application/json, text/plain, */*',
            'Content-Type':'application/json;charset=UTF-8',
            'Accept-Language':'zh-CN,zh;q=0.9'
        }
        name='wurong903'
        password='dfgx1234'
        data = {"name":name,"password":password,"payPassword":"2745","code":d_yzm,"promoteCode":"","bankName":""}
        data1 = json.dumps(data)

        response1 = sess.post(url,data=data1,headers=headers)
        print(response1.text)
if __name__ == '__main__':
    al = autologin()
    al.login('10gcw')
复制代码

抓包使用的工具 telerik fiddler 

目前这段代码,验证码的准确率有待提高,10次大概有1次识别不了。1.需要增加机器学习   2.这段代码改一下,可以登录券商

posted @   东哥加油!!!  阅读(304)  评论(0编辑  收藏  举报
编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
点击右上角即可分享
微信分享提示