验证码 识别

Posted 52shaidan

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了验证码 识别相关的知识,希望对你有一定的参考价值。

#!/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.这段代码改一下,可以登录券商

以上是关于验证码 识别的主要内容,如果未能解决你的问题,请参考以下文章

python验证码识别极验滑动验证码识别

利用云识别过简单验证码实例(源代码分享)

python 验证码识别示例 简单验证码识别

python 验证码识别示例 简单验证码识别

Python 代码实现验证码识别

爬虫日记-验证码识别