在线翻译实现代码如下
import requests
import json
import hashlib
class ifanyi:
def __init__(self,q):
self.headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36'
}
self.data = {
'from': 'auto',
'to': 'auto',
'q': q
}
sign = (hashlib.md5(("6key_web_fanyiifanyiweb8hc9s98e" + q).encode('utf-8')).hexdigest())[0:16]
self.url = 'http://ifanyi.iciba.com/index.php?c=trans&m=fy&client=6&auth_user=key_web_fanyi&sign=' + sign
def getdata(self):
res = requests.post(url=self.url, headers=self.headers, data=self.data).json()
print(res['content']['out'])
if __name__=='__main__':
q = input('请输入要翻译的内容:')
ifanyi = ifanyi(q)
ifanyi.getdata()
详解python使用金山词霸的翻译功能(调试工具断点的使用)
https://www.zhangshengrong.com/p/v710KdP4XM/