var r = function (e) { var t = n.md5(navigator.appVersion), r = "" + newDate().getTime(), i = r + parseInt(10 * Math.random(), 10); return { ts: r, bv: t, salt: i, sign: n.md5("fanyideskweb" + e + i + "Nw(nmmbP%A-r6U3EUn]Aj"), }; };
import requests import time import hashlib import random import demjson
defget_ts_bv_salt_sign(e): t = hashlib.md5( "5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.113 Safari/537.36".encode('utf-8')).hexdigest() r = int(time.time()*1000) i = r + int(random.random()*10) ts = r, bv = t, salt = i, sign = hashlib.md5(("fanyideskweb" + e + str(i) + "Nw(nmmbP%A-r6U3EUn]Aj").encode('utf-8')).hexdigest()
headers = { 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.113 Safari/537.36', 'Referer': 'http://fanyi.youdao.com/', 'Cookie': 'this is your cookie', } url = 'http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule' data = { 'i': e, 'from': 'AUTO', 'smartresult': 'dict', 'client': 'fanyideskweb', 'salt': salt, 'sign': sign, 'ts': ts, 'bv': bv, 'doctype': 'json', 'version': '2.1', 'keyfrom': 'fanyi.web', 'action': 'FY_BY_REALTlME', } res = requests.post(url=url, headers=headers, data=data) res = demjson.decode(str(res.text)) return res['translateResult'][0][0]['tgt']
if __name__ == '__main__': e = input("请输入要翻译的词:") result = get_ts_bv_salt_sign(e) print("翻译结果为:"+result)