import requests import json def translation(): #发送翻译内容的网址 url = "http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&smartresult=ugc&sessionFrom=null" #翻译时需要发送的数据,目前只可以中英文互相翻译 send_data = { ‘i‘:‘‘, ‘from‘:‘AUTO‘, ‘to‘:‘AUTO‘, ‘smartresult‘:‘dict‘, ‘client‘:‘fanyideskweb‘, ‘doctype‘:‘json‘, ‘version‘:‘2.1‘, ‘keyfrom‘:‘fanyi.web‘, ‘action‘:‘FY_BY_CLlCKBUTTON‘, ‘typoResult‘:‘true‘, } content = input(‘输入你想翻译的内容:‘) send_data[‘i‘] = content html = requests.post(url,data=send_data) txt = json.loads(html.text) tra_text = txt[‘translateResult‘][0][0][‘tgt‘] # print(‘翻译结果为:‘ + tra_text) return ‘翻译结果为:‘ + tra_text content = translation() print(content)
时间: 2024-12-19 10:35:23