云打码案例 python

1.云打码 http://www.yundama.com/   下载 YDMHTTPDemo3.x(python3)

2.将文件解压至项目目录下 命名如yzm_util.py

3.注册云打码平台,普通用户和开发者用户各一个,在开发者用户下增加我的新软件,得到软件代码和通讯密匙,在yzm_util.py中修改相应代码

4. 将yzm_util.py post_url()方法后修改内容如下:

    ######################################################################
def get_code(filename):
    # 普通用户名
    username    = 'xxxx'

    # 普通用户密码
    password    = 'xxxx'

    # 软件ID,开发者分成必要参数。登录开发者后台【我的软件】获得!
    appid       = xxxx

    # 软件密钥,开发者分成必要参数。登录开发者后台【我的软件】获得!
    appkey      = 'xxxx'

    # 图片文件
    filename    = filename

    # 验证码类型,# 例:1004表示4位字母数字,不同类型收费不同。请准确填写,否则影响识别率。在此查询所有类型 http://www.yundama.com/price.html
    codetype    = 1005

    # 超时时间,秒
    timeout     = 60

    # 检查
    if (username == 'username'):
        print('请设置好相关参数再测试')
    else:
        # 初始化
        yundama = YDMHttp(username, password, appid, appkey)

        # 登陆云打码
        uid = yundama.login();
        # print('uid: %s' % uid)

        # 查询余额
        balance = yundama.balance();
        # print('balance: %s' % balance)

        # 开始识别,图片路径,验证码类型ID,超时时间(秒),识别结果
        cid, result = yundama.decode(filename, codetype, timeout);
        # print('cid: %s, result: %s' % (cid, result))
        return result
    ######################################################################

代码:

# -*- coding: utf-8 -*-
# @Time : 2020/4/20 18:59
# @Author : Oneqq
# @File : 26.云打码使用案例.py
# @Software: PyCharm

import requests
from fake_useragent import UserAgent
from Pratice1.yzm_util import get_code


def get_img():
    img_url = "http://www.yundama.com/index/captcha"
    response = session.get(img_url, headers=headers)
    with open('yzm.jpg', 'wb') as f:
        f.write(response.content)
    code = get_code('yzm.jpg')
    print(code)
    return code


def do_login(code):
    login_url = "http://www.yundama.com/index/login"
    params = {
        "username": "xxxx",
        "password": "xxxx",
        "utype": "1",
        "vcode": code
    }
    response = session.get(login_url, headers=headers, params=params)
    print(response.text)


if __name__ == '__main__':
    index_url = "http://www.yundama.com/"
    headers = {
        "User-Agent": UserAgent().chrome
    }
    session = requests.Session()
    response = session.get(index_url, headers=headers)
    code = get_img()
    do_login(code)

结果:登录成功

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章