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)
結果:登錄成功