import base64
import json
import hashlib
import requests
cookies = {
'sajssdk_2015_cross_new_user': '1',
'sensorsdata2015jssdkcross': '%7B%22distinct_id%22%3A%2218d3a22e6af3f2-07052966993d9d-26001951-2073600-18d3a22e6b0b73%22%2C%22%24device_id%22%3A%2218d3a22e6af3f2-07052966993d9d-26001951-2073600-18d3a22e6b0b73%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E7%9B%B4%E6%8E%A5%E6%B5%81%E9%87%8F%22%2C%22%24latest_referrer%22%3A%22%22%2C%22%24latest_referrer_host%22%3A%22%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC_%E7%9B%B4%E6%8E%A5%E6%89%93%E5%BC%80%22%7D%7D',
'forever': '1',
'acw_tc': '784e2c8117060834974581452e4b31790cd57c58dc4c9589f1648b3590a40c',
'SESSION': 'c6221c7d-720a-4411-9000-f8e1f52274a3',
}
headers = {
'Referer': 'https://www.hfax.com/login.html',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
'apiVersion': '1.9',
'ds': 'home',
}
response = requests.get('https://www.hfax.com/pc-api/common/imageCode/login', cookies=cookies, headers=headers)
#获取验证码图片,打码平台图鉴 http://www.ttshitu.com/
img_base64 = response.json()['data']['base64Str'].split('base64,')[1]
img_token = response.json()['data']['token']
decoded_img = base64.b64decode(img_base64)
with open('1.jpg', 'wb') as fp:
fp.write(decoded_img)
def base64_api(uname, pwd, img, typeid):
with open(img, 'rb') as f:
base64_data = base64.b64encode(f.read())
b64 = base64_data.decode()
data = {"username": uname, "password": pwd, "typeid": typeid, "image": b64}
result = json.loads(requests.post("http://api.ttshitu.com/predict", json=data).text)
if result['success']:
return result["data"]["result"]
else:
#!!!!!!!注意:返回 人工不足等 错误情况 请加逻辑处理防止脚本卡死 继续重新 识别
return result["message"]
return ""
img_path = '1.jpg'
imgCode = base64_api('username','password',img_path,typeid=3)
print(imgCode)
# 密码加密
def md5_salt(password):
password_with_salt = password + 'TuD00Iqz4ge7gzIe2rmjSAFFKtaIBmnr8S'
md5 = hashlib.md5()
md5.update(password_with_salt.encode('utf-8'))
encrypted_password = md5.hexdigest()
return encrypted_password
json_data = {
'username': '17688962828',
'password': md5_salt('zy4479nan'),
'imgCode': imgCode,
'imgToken': img_token,
}
response = requests.post('https://www.hfax.com/pc-api/user/login', cookies=cookies, headers=headers, json=json_data)
print(response.text)
标签:img,22%,base64,json,惠金,password,data,MD5
From: https://www.cnblogs.com/xchuan/p/17985098