有道翻译逆向

js源码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
define("newweb/common/service", ["./utils", "./md5", "./jquery-1.7"], function(e, t) {
var n = e("./jquery-1.7");
e("./utils");
e("./md5");
var r = function (e) {
var t = n.md5(navigator.appVersion)
, r = "" + (new Date).getTime()
, i = r + parseInt(10 * Math.random(), 10);
return {
ts: r,
bv: t,
salt: i,
sign: n.md5("fanyideskweb" + e + i + "Ygy_4c=r#e#4EX^NUGUc5")
}
};
// e = 翻译的字符串, i = 字符串形式的js时间戳+一位整数

python实现代码

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):
# 13位时间戳
lts = str(int(time.time() * 1000))
# 时间戳+一个随机整数
salt = str(int(time.time() * 10000))
# 写死的两个参数+翻译的字符+salt
sign = "fanyideskweb" + word + salt + "Y2FYu%TNSbMCxc3t2u^XT"
# md5 加密字符
sign = hashlib.md5(sign.encode()).hexdigest()

data = {"i": word,
"from": "AUTO",
"to": "AUTO",
"smartresult": "dict",
"client": "fanyideskweb",
# 时间戳14位
"salt": salt,
# 加密的数据
"sign": sign,
# 时间戳13位
"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')