有道翻译接口逆向_python有道翻译api(2)

import hashlib
from urllib.parse import urlencode

def get_timestamp():
return int(datetime.datetime.now().timestamp() * 1000)

def get_key():
# 主要是获取key等参数
url = “https://dict.youdao.com/webtranslate/key”
mysticTime = get_timestamp()
tmp_sign = f"client=fanyideskweb&mysticTime={mysticTime}&product=webfanyi&key=asdjnjfenknafdfsdfsd"
sign = hashlib.md5(tmp_sign.encode(“utf8”)).hexdigest()
# 参数
params = {
‘keyid’: ‘webfanyi-key-getter’,
‘sign’: sign,
‘client’: ‘fanyideskweb’,
‘product’: ‘webfanyi’,
‘appVersion’: ‘1.0.0’,
‘vendor’: ‘web’,
‘pointParam’: ‘client,mysticTime,product’,
‘mysticTime’: mysticTime,
‘keyfrom’: ‘fanyi.web’,
‘mid’: 1,
‘screen’: 1,
‘model’: 1,
‘network’: ‘wifi’,
‘abtest’: ‘0’,
‘yduuid’: ‘abcdefg’,
}

url_with_params = f"{url}?{urlencode(params)}"

headers = {
    'Accept': 'application/json, text/plain, \*/\*',
    'Accept-Language': 'zh-CN,zh;q=0.9',
    'Cache-Control': 'no-cache',
    'Connection': 'keep-alive',
    'Origin': 'https://fanyi.youdao.com',
    'Pragma': 'no-cache',
    'Referer': 'https://fanyi.youdao.com/',
    'Sec-Fetch-Dest': 'empty',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'same-site',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36',
    'Sec-Ch-Ua': '"Chromium";v="122", "Not(A:Brand";v="24", "Google Chrome";v="122"',
    'Sec-Ch-Ua-Mobile': '?0',
    'Sec-Ch-Ua-Platform': '"Windows"'
}

# 请求
response = requests.get(url_with_params, headers=headers, data={})
json_data = json.loads(response.text)
# 获取 key
key = json_data['data']['secretKey']
return key

def send(chinese):
url = “https://dict.youdao.com/webtranslate”
mysticTime = get_timestamp()
# sign 是 client=fanyideskweb&mysticTime=1711295634744&product=webfanyi&key=fsdsogkndfokasodnaso
tmp_sign = f"client=fanyideskweb&mysticTime={mysticTime}&product=webfanyi&key={get_key()}"
s

  • 5
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值