请求发送操作步骤
- 构造请求
- 请求发送成功后将返回的数据进行base64反混淆和base64解码
- 对base64解码后的数据进行aes解密
- 对解密后的数据进行数据反填充
- 对反填充后的数据转换成字符串
- 将json格式的字符串进行反序列化
- 获取想要的数据
import base64
import hashlib
import json
import time
from Crypto.Cipher import AES
from Crypto.Util.Padding import unpad, pad
import requests
headers={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36",
"Referer": "https://fanyi.youdao.com/",
"Cookie": "OUTFOX_SEARCH_USER_ID=2062882188@10.105.253.23; OUTFOX_SEARCH_USER_ID_NCOO=702963757.8111634"
}
url="https://dict.youdao.com/webtranslate"
t=str(int(time.time()*1000))
temp=f"client=fanyideskweb&mysticTime={t}&product=webfanyi&key=fsdsogkndfokasodnaso"
md5_obj=hashlib.md5()
md5_obj.update(temp.encode())
sign=md5_obj.hexdigest()
res=requests.post(url,data={
"i": "hello",
"from": "auto",
"to":"",
"domain": "0",
"dictResult": "true",
"keyid": "webfanyi",
"sign": sign,
"client": "fanyideskweb",
"product": "webfanyi",
"appVersion": "1.0.0",
"vendor": "web",
"pointParam": "client,mysticTime,product",
"mysticTime": t,
"keyfrom": "fanyi.web"
},headers=headers)
res=res.text
res=res.replace('-','+').replace('_','/')
decrypt_data=base64.b64decode(res)
o='ydsecret://query/key/B*RGygVywfNBwpmBaZg*WT7SIOUP2T0C9WHMZN39j^DAdaZhAnxvGcCY6VYFwnHl'
n='ydsecret://query/iv/C@lZe2YzHtZ2CYgaXKSVfsb7Y4QWHjITPPZ0nQp87fBeJ!Iv6v^6fvi2WN@bYpJ4'
def g(v):
md5=hashlib.md5()
md5.update(v.encode())
return md5.digest()
key=g(o)
iv=g(n)
aes=AES.new(key,AES.MODE_CBC,iv)
data=aes.decrypt(decrypt_data)
print("data:::",data)
data=unpad(data,16)
print(data.decode())
data=json.loads(data.decode())
print(data["translateResult"])