本帖最后由 临时号 于 2022-9-3 12:56 编辑 import re
import requests
def n(r, o):
t = 0
while t < len(o) - 2:
a = o[t + 2]
if a >= "a":
a = ord(a[0]) - 87
else:
a = int(a)
if "+" == o[t + 1]:
a = r >> a
else:
a = r << a
if "+" == o[t]:
r = r + a & 4294967295
else:
r = r ^ a
t += 3
return r
def a(r):
if type(r) == list:
o = 0
t = list(len(r))
while o < len(r):
t[o] = r[o]
o += 1
return t
return r
def e(r):
global i
o = re.findall("[\uD800-\uDBFF][\uDC00-\uDFFF]",r)
if o == []:
t = len(r)
if t > 30:
r = r[0:10] + r[t // 2 - 5:t // 2 - 5 + 10] + r[-10:]
else:
e = re.split("[\uD800-\uDBFF][\uDC00-\uDFFF]",r)
C = 0
h = len(e)
f = []
while h > C:
"" != e[C] and f.extend(a(e[C].split("")))
C != h - 1 and f.append(o[C])
C += 1
g = len(f)
if g > 30:
r = "".join(f[0:10]) + "".join(f[g // 2 - 5:g // 2 + 5]) + "".join(f[-10:])
u = None
l = chr(103) + chr(116) + chr(107)
if None != i:
u = i
else:
i = "320305.131321201" or ""
u = i or ""
d = u.split(".")
m = int(d[0]) or 0
s = int(d[1]) or 0
S = [0 for count in range(1000)]
c = 0
v = 0
while v < len(r):
A = ord(r[v])
if 128 > A:
S[c] = A
c += 1
else:
if 2048 > A:
S[c] = A >> 6 | 192
c += 1
else:
if 55296 == (64512 & A) and v + 1 < len(r) and 56320 == (64512 & ord(r[v+1])):
v += 1
A = 65536 + ((1023 & A) << 10) + (1023 & ord(r[v]))
S[c] = A >> 18 | 240
c += 1
S[c] = A >> 12 & 63 | 128
c += 1
else:
S[c] = A >> 12 | 224
c += 1
S[c] = A >> 6 & 63 | 128
c += 1
S[c] = 63 & A | 128
c += 1
v += 1
for count in range(S.count(0)):
S.remove(0)
p = m
F = chr(43) + chr(45) + chr(97) + (chr(94) + chr(43) + chr(54))
D = chr(43) + chr(45) + chr(51) + (chr(94) + chr(43) + chr(98)) + (chr(43) + chr(45) + chr(102))
b = 0
while b < len(S):
p += S[b]
p = n(p,F)
b += 1
p = n(p,D)
p ^= s
if 0 > p:
p = (2147483647 & p) + 2147483648
p %= 1e6
return str(int(p)) + "." + str(int(p) ^ m)
headers = {
"User-Agent":"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36",
"Cookie":"BIDUPSID=A92A6802F7D86AED4D4E206949C7BDAD; PSTM=1650383456; REALTIME_TRANS_SWITCH=1; FANYI_WORD_SWITCH=1; HISTORY_SWITCH=1; SOUND_SPD_SWITCH=1; SOUND_PREFER_SWITCH=1; BDUSS=lKbG5Van54QlllVVlRfkZtSHB5UVFyZDJRQTFYVkZiRDBvMVk4Znc4OUpwWTlpRVFBQUFBJCQAAAAAAAAAAAEAAAChTKa30-7W5tL40NAzNDUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEkYaGJJGGhiUU; BDUSS_BFESS=lKbG5Van54QlllVVlRfkZtSHB5UVFyZDJRQTFYVkZiRDBvMVk4Znc4OUpwWTlpRVFBQUFBJCQAAAAAAAAAAAEAAAChTKa30-7W5tL40NAzNDUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEkYaGJJGGhiUU; APPGUIDE_10_0_2=1; BAIDUID=78B7B37E0E97AF8B823966378D315602:FG=1; newlogin=1; H_PS_PSSID=; BDORZ=FFFB88E999055A3F8A630C64834BD6D0; Hm_lvt_64ecd82404c51e03dc91cb9e8c025574=1660558471,1660720878,1660799867,1660886179; ab_sr=1.0.1_MDEwYjlkYzllNDcwNDU0Nzk3NjVhNzAzNmMyZTRhNTNjNmE0Y2ZlNjJkZWZmODc2OWM5ZjQ2NzQxMDk3MTU1MjkxN2Y5MzdiYjYwNDRlOWNmYTYyZTcxZTdiZjAwOGMxZGFiOWM2NmFhYjMzMjQxNWE0NTVlODY2ZDg5MTgzZjVkYzVlYmI5MDA0MmUyNTNjMDBjNWQ3Zjg5NzFkM2IzMzk0Y2ZiNGQxNjRkYzBhYzdhNDY3MTU3ZGUzMzMxNTc3; BAIDUID_BFESS=78B7B37E0E97AF8B823966378D315602:FG=1; delPer=0; PSINO=6; BA_HECTOR=8425858la08l20agak8i397n1hfum9i17; ZFY=x65kMuW:BavVpgIHCMW7HIirB1oQin3GXivMNQ6Y96Hc:C; Hm_lpvt_64ecd82404c51e03dc91cb9e8c025574=1660904815"
}
word = input("请输入待翻译的内容:")
i = "320305.131321201"
data = {
"from":"en",
"to":"zh",
"query":word,
"transtype":"realtime",
"simple_means_flag":"3",
"sign":e(word),
"token":"c4882f7699e4c8b6fce27da420eff7f2",
"domain":"common"
}
response = requests.post("https://fanyi.baidu.com/v2transapi?from=en&to=zh",headers=headers,data=data)
if response.status_code == 200:
response.encoding = "utf-8"
print(response.json()["trans_result"]["data"][0]["dst"])
|