|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
话说有道翻译都被你们玩坏了,不说有后门(去掉那个下划线) 即使是逆向有道 据大佬们说 也是狠easy的
今天我们来一个稍稍比有道难些的 它就是百度翻译
- import requests
- import execjs
- class baidufy(object):
- def __init__(self):
- self._from="zh"
- self._to="en"
- self._word="test"
- self._url="https://fanyi.baidu.com/v2transapi?from=en&to=zh"
- self._headers={
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36' ,
- 'Cookie': 'BAIDUID=C7638744D857E9E04845B17AF533C51F:FG=1; Hm_lvt_64ecd82404c51e03dc91cb9e8c025574=1622890608; Hm_lpvt_64ecd82404c51e03dc91cb9e8c025574=1622890608; REALTIME_TRANS_SWITCH=1; FANYI_WORD_SWITCH=1; HISTORY_SWITCH=1; SOUND_SPD_SWITCH=1; SOUND_PREFER_SWITCH=1; __yjs_duid=1_dd39d74ec48d01dbbc90d80a1ac368091622890604663',
- }
-
- def getsign(self):
- with open("baidufanyi.js","r",encoding="utf8") as f:
- jscode=f.read()
- return execjs.compile(jscode).call("get_sign",self._word)
- def setfrom(self,f):
- self._from=f
- def setto(self,f):
- self._to=f
- def setword(self,f):
- self._word=f
- def getres(self):
- data={
- 'from': self._from,
- 'to': self._to,
- 'query':self._word,
- 'transtype': 'enter',
- 'simple_means_flag': 3,
- 'sign': self.getsign(),
- 'token': '051d57076542d98fc5fad9a6d1baf2e8',
- 'domain': 'common'
- }
- return requests.post(url=self._url,headers=self._headers,data=data)
- fy=baidufy()
- fy.setword("猫狗大战")
- fy.setfrom("zh")
- fy.setto("en")
- res=fy.getres()
- print(res.json()["trans_result"]["data"][0]["dst"])
- fy.setword("recent")
- fy.setfrom("en")
- fy.setto("zh")
- res=fy.getres()
- print(res.json()["trans_result"]["data"][0]["dst"])
- fy.setword("this is a test text")
- res=fy.getres()
- print(res.json()["trans_result"]["data"][0]["dst"])
- fy.setword("我们伟大的祖国")
- fy.setfrom("zh")
- fy.setto("en")
- res=fy.getres()
- print(res.json()["trans_result"]["data"][0]["dst"])
复制代码
测试样本:
PS E:\wp> py test4.py
Cat and dog battle
最近的
这是一个测试文本
Our great motherland
PS E:\wp>
PS E:\wp>
|
|