import json
import time
import hashlib
from Crypto.Cipher import AES
from Crypto.Util.Padding import unpad
import requests
o = str(int(time.time()*1000))
def sign():
# e = 'asdjnjfenknafdfsdfsd'
# u = 'fanyideskweb'
# d = 'webfanyi'
q = 'client=fanyideskweb&mysticTime='+str(o)+'&product=webfanyi&key=fsdsogkndfokasodnaso'
a = hashlib.md5(q.encode()).hexdigest()
return a
def decrypt( decrypt_str,iv,key):
key_md5 = hashlib.md5((key).encode('utf-8')).digest()
iv_md5 = hashlib.md5((iv).encode('utf-8')).digest()
aes = AES.new(key=key_md5, mode=AES.MODE_CBC, iv=iv_md5)
code = aes.decrypt(base64.urlsafe_b64decode(decrypt_str))
return unpad(code, AES.block_size).decode('utf8')
def get_data(q):
headers = {
'Host':'dict.youdao.com',
'Origin':'https://fanyi.youdao.com',
'Referer':'https://fanyi.youdao.com/',
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36 Edg/118.0.2088.61",
'Cookie':'OUTFOX_SEARCH_USER_ID_NCOO=1918452785.9332309; [email protected];'
}
url = 'https://dict.youdao.com/webtranslate'
data = {
'i': q,
'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': str(o),
'keyfrom': 'fanyi.web',
'mid': 1,
'screen': 1,
'model': 1,
'network': 'wifi',
'abtest': 0,
'yduuid': 'abcdefg'
}
res = requests.post(url,data=data,headers=headers)
return res.text
def judge_language(text):
for char in text:
# 判断字符的 Unicode 范围
if '\u4e00'