原来python也能对实现简单的搜狗翻译
import hashlib
import requests
import re
if __name__ == '__main__':
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36 Edg/105.0.1343.42',
"x-requested-with": "XMLHttpRequest",
"origin": "https://fanyi.baidu.com",
"referer": "https://fanyi.baidu.com/?aldtype=16047",
"Cookie":"ssuid=7578450800; IPLOC=CN3100; SUID=F032E28B1639960A000000006232CC75; SUV=1651048972958935; SMYUV=1654738753827713; ABTEST=7|1663744120|v17; SNUID=1824051C2520CF0CB8634BB5262C535A; wuid=1663744120080; FQV=600dbc0b73aa939b0ef6f5541d5e890c; translate.sess=9e2ec77e-1da9-4f86-9af3-dd742a75c4f5; SGINPUT_UPSCREEN=1663744120480"
}
text = "hello world"
url2=f"https://fanyi.sogou.com/text?keyword={text}&transfrom=auto&transto=zh-CHS&model=general"
# content = requests.post(url2, headers=headers, data=data).content.decode()
content = requests.get(url2, headers=headers).content.decode()
uuid = re.findall(r'<meta name="reqinfo" content="uuid:(.*?),', content)[0]
url = "https://fanyi.sogou.com/api/transpc/text/result"
t = f"autozh-CHS{text}109984457"
tt = hashlib.md5(t.encode()).hexdigest()
data = {"from": "auto", "to": "zh-CHS", "text": text, "client": "pc", "fr": "browser_pc", "needQc": 1,
"s": tt, "uuid": uuid, "exchange": False}
print(data)
content = requests.post(url, headers=headers, data=data).content.decode()
print(content)
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/61501.html