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