1、网址
https://fanyi.youdao.com/
2、分析网站
这里我们能进行一个数据的翻译,代码如下,注意
https://fanyi.youdao.com/translate_osmartresult=dict&smartresult=rule当中的_o要去除掉
import requests
url = "https://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule"
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3878.400 QQBrowser/10.8.4518.400",
"Cookie": 'P_INFO=null; OUTFOX_SEARCH_USER_ID_NCOO=947736847.773168; OUTFOX_SEARCH_USER_ID="1198499806@10.105.137.202"; _ga=GA1.2.1663751421.1637331565; JSESSIONID=aaaTr_RbM-Yyd-dxtzl-x; ___rl__test__cookies=1648384942617',
"Referer": "https://fanyi.youdao.com/"
}
params = {
"i": "我们在这里做分析",
"from": "AUTO",
"to": "AUTO",
"smartresult": "dict",
"client": "fanyideskweb",
"salt": "16483849426281",
"sign": "8eeff53de46e1048e558b6b82a98d022",
"lts": "1648384942628",
"bv": "5fc0aac3ed3becb0c002163530da8bea",
"doctype": "json",
"version": "2.1",
"keyfrom": "fanyi.web",
"action": "FY_BY_REALTlME"
}
resp = requests.post(url, headers=headers, data=params)
print(resp)
print(resp.json())
结果如下
3、数据解密
上面的数据是需要我们解密的
首先ITs是一个时间戳,在这个网站进行验证https://tool.lu/timestamp/
注意,这里我们输入1648384942628没有最后三位,只有前10位数。
这时候我们搜索一下
我们搜索translate_o
点击进去之后呢,然后我们crtf+f,搜索本页面translate_o
我们在本函数后面加上一个断点,然后再刷新一下页面
这里就是我们得到的加密数据,我们需要没有加密的数据,那这时开始往回掉
这里就是我们需要的数据了。主要还是获得变量r的数据
这里面的n就是我们需要翻译的数据。
我们进入v.generateSaltSign(n);函数中
我们在console中调试一下
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")
}
得到里面变量的值
"5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3878.400 QQBrowser/10.8.4518.400"
from hashlib import md5
appVersion = "5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3878.400 QQBrowser/10.8.4518.400"
def r(e):
t = md5(appVersion.encode()).hexdigest() #hexdigest()是将数据转换为16位
print(t)
r('我们在这里做分析')
我们比较一下,这里数据都是相同的。
对这些变量进行解密
from hashlib import md5
import time
import random
appVersion = "5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3878.400 QQBrowser/10.8.4518.400"
def r(e):
#var t = n.md5(navigator.appVersion)
t = md5(appVersion.encode()).hexdigest() #hexdigest()是将数据转换为16位
print(t)
#r = "" + (new Date).getTime() #时间戳
r = str(int(time.time()*1000))
print(r)
#i = r + parseInt(10 * Math.random(), 10);
i = r + str(random.randint(0, 9))
print(i)
# return {
# ts: r,
# bv: t,
# salt: i,
# sign: n.md5("fanyideskweb" + e + i + "Ygy_4c=r#e#4EX^NUGUc5")
# }
return {
'ts': r,
'bv': t,
'salt': i,
'sign': md5(("fanyideskweb" + e + i + "Ygy_4c=r#e#4EX^NUGUc5").encode()).hexdigest()
}
print(r('我们在这里做分析'))
代码
import requests
from hashlib import md5
import time
import random
url = "https://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule"
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3878.400 QQBrowser/10.8.4518.400",
"Cookie": 'P_INFO=null; OUTFOX_SEARCH_USER_ID_NCOO=947736847.773168; OUTFOX_SEARCH_USER_ID="1198499806@10.105.137.202"; _ga=GA1.2.1663751421.1637331565; JSESSIONID=aaaTr_RbM-Yyd-dxtzl-x; ___rl__test__cookies=1648384942617',
"Referer": "https://fanyi.youdao.com/"
}
appVersion = "5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3878.400 QQBrowser/10.8.4518.400"
def r(e):
#var t = n.md5(navigator.appVersion)
t = md5(appVersion.encode()).hexdigest() #hexdigest()是将数据转换为16位
# print(t)
#r = "" + (new Date).getTime() #时间戳
r = str(int(time.time()*1000))
# print(r)
#i = r + parseInt(10 * Math.random(), 10);
i = r + str(random.randint(0, 9))
# print(i)
# return {
# ts: r,
# bv: t,
# salt: i,
# sign: n.md5("fanyideskweb" + e + i + "Ygy_4c=r#e#4EX^NUGUc5")
# }
return {
'ts': r,
'bv': t,
'salt': i,
'sign': md5(("fanyideskweb" + e + i + "Ygy_4c=r#e#4EX^NUGUc5").encode()).hexdigest()
}
def fanyi(word):
data = r(word)
params = {
"i": "我们在这里做分析",
"from": "AUTO",
"to": "AUTO",
"smartresult": "dict",
"client": "fanyideskweb",
"salt": data['salt'],
"sign": data['sign'],
"lts": data['ts'],
"bv": data['bv'],
"doctype": "json",
"version": "2.1",
"keyfrom": "fanyi.web",
"action": "FY_BY_REALTlME"
}
resp = requests.post(url, headers=headers, data=params)
return resp.json()
if __name__ == '__main__':
while True:
word = input('输入需要翻译的内容:')
data = r(word)
results = fanyi(word)
print(results)
#提取内容
r = results['translateResult'][0]
print(r)
print(r[0]['src']) #提取中文
print(r[0]['tgt']) #提取英文
结果
输入需要翻译的内容:我们在这里做分析
{'type': 'ZH_CN2EN', 'errorCode': 0, 'elapsedTime': 0, 'translateResult': [[{'src': '我们在这里做分析', 'tgt': 'We are here to do analysis'}]]}
[{'src': '我们在这里做分析', 'tgt': 'We are here to do analysis'}]
我们在这里做分析
We are here to do analysis
|