-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathyoudao.py
More file actions
63 lines (53 loc) · 1.98 KB
/
Copy pathyoudao.py
File metadata and controls
63 lines (53 loc) · 1.98 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""
Ark Lu
2020-06-24
Version 1.0
"""
import requests
import hashlib, time, random
def md5(word):
word = word.encode()
result = hashlib.md5(word)
return result.hexdigest()
def youdao(word):
headers = {
'Accept': 'application / json, text / javascript, * / *; q = 0.01',
'Accept-Encodingg': 'zip, deflate',
'Accept - Language': 'en-US,en;q=0.5',
'Connection': 'keep-alive',
'Content-Length': '255',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Cookie': 'JSESSIONID=abcqvlXgyrNd2bHGVgClx; _ntes_nnid=51b2078cc4077e13288249f78ef60584,1592830656555; OUTFOX_SEARCH_USER_ID_NCOO=246273121.26279658; OUTFOX_SEARCH_USER_ID=1630396520@10.169.0.102; YOUDAO_MOBILE_ACCESS_TYPE=1; ___rl__test__cookies=1592830707900',
'Host': 'fanyi.youdao.com',
'Origin': 'http://fanyi.youdao.com',
'Referer': 'http://fanyi.youdao.com/?keyfrom=dict2.top',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:77.0) Gecko/20100101 Firefox/77.0',
'X-Requested-With': 'XMLHttpRequest'
}
t = md5(
"5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36")
r = str(int(time.time() * 1000))
i = r + str(random.randint(0, 9))
words = {
'i': word,
'from': "AUTO",
'to': "AUTO",
'smartresult': "dict",
'client': "fanyideskweb",
'salt': i,
'sign': md5("fanyideskweb" + word + i + "mmbP%A-r6U3Nw(n]BjuEU"),
'ts': r,
'bv': t,
'doctype': "json",
'version': "2.1",
'keyfrom': "fanyi.web",
'action': "FY_BY_CLICKBUTTION"
}
url = 'http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule'
result = requests.post(url, data=words, headers=headers)
print(result)
print(result.text)
if __name__ == '__main__':
while 1:
word = input("Please input your word:")
youdao(word)