1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| import time import hashlib import requests
def get_fanyi(word): lts = str(int(time.time() * 1000)) salt = str(int(time.time() * 10000)) sign = "fanyideskweb" + word + salt + "Y2FYu%TNSbMCxc3t2u^XT" sign = hashlib.md5(sign.encode()).hexdigest()
data = {"i": word, "from": "AUTO", "to": "AUTO", "smartresult": "dict", "client": "fanyideskweb", "salt": salt, "sign": sign, "lts": lts, "bv": 'd771cbe0c376715add7059261c9e06bd', "doctype": "json", "version": "2.1", "keyfrom": "fanyi.web", "action": "FY_BY_REALTlME" } url = 'https://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule' header = { 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.60 Safari/537.36', 'Referer': 'https://fanyi.youdao.com/', 'cookie': 'OUTFOX_SEARCH_USER_ID=-1711366876@10.108.160.105; OUTFOX_SEARCH_USER_ID_NCOO=528854206.9578509; ' 'fanyi-ad-closed=0; JSESSIONID=aaab35aMiB_2j8wyyH0-x; fanyi-ad-id=305426; ' '___rl__test__cookies=1649078361368 ' } resp = requests.post(url=url, headers=header, data=data) print(resp.json()['translateResult'][0][0]['tgt'])
if __name__ == '__main__': get_fanyi('dog')
|