首先,获取相应数据,做对比。
通过对比我们发现就这三个不同,全局搜索不同的三个。
同过查找发现是MD5加密。此时我们用python实现同样的功能就行。
通过本地输出,测的r是时间戳
console.log()
i 是时间戳后面加了个随机数,1到9,不包括10.
sign是左右两端字符串加上中间的+时间戳+翻译的词,然后用md5实现
代码
import requests
import time
import random
from hashlib import md5
headers={
"Accept":"application/json, text/javascript, */*; q=0.01",
"Accept-Encoding":"gzip, deflate",
"Accept-Language":"zh,zh-CN;q=0.9",
"Connection":"keep-alive",
"Content-Length":"256",
"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8",
"Cookie":"OUTFOX_SEARCH_USER_ID=1224775190@10.108.160.101; JSESSIONID=aaa90ZzZ5tX6TdNw5PPCx; OUTFOX_SEARCH_USER_ID_NCOO=881210050.4581219; ___rl__test__cookies=1611311616229",
"Host":"fanyi.youdao.com",
"Origin":"http://fanyi.youdao.com",
"Referer":"http://fanyi.youdao.com/",
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36",
"X-Requested-With":"XMLHttpRequest",
}
url=("http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule")
shu=input("请输入需要翻译的文字")
ts=str(int(time.time()*1000))
salt=ts+str(random.randint(0,9))
strl_= "fanyideskweb" + shu + salt + "Tbh5E8=q6U3EXe+&L[4c@"
md=md5()
md.update(strl_.encode())
sign=md.hexdigest()
data={
"i":shu,
"from": 'AUTO',
"to": 'AUTO' ,
"smartresult": 'dict',
"client": 'fanyideskweb',
"salt": salt,
"sign": sign,
"lts": ts,
"bv": 'eac2bf78c46bf1bab5b4558752481e4a',
"doctype": 'json',
"version": '2.1',
"keyfrom": 'fanyi.web',
"action": 'FY_BY_CLICKBUTTION',
}
resd=requests.post(url=url,headers=headers,data=data)
print(resd.json())