不知道这样行不行:from requests import post
from easygui import enterbox, msgbox
from json import loads
while True:
x = enterbox(msg='输入要翻译的内容', title='简易翻译器')
url = 'http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule'
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36 Edg/84.0.522.40'}
data = {}
data['from'] = 'AUTO'
data['i'] = x
data['to'] = 'AUTO'
data['smartresult'] = 'dict'
data['client'] = 'fanyideskweb'
data['salt'] = '15952537871928'
data['sign'] = '71811dbd64fd2b55b3c18ff0a5bf248f'
data['ts'] = '1595253787192'
data['bv'] = 'b262489bd5affeda81a1ff31595ae4e8'
data['doctype'] = 'json'
data['version'] = '2.1'
data['keyfrom'] = 'fanyi.web'
data['action'] = 'FY_BY_CLICKBUTTION'
r = requests.post(url,
data=data,
headers=headers)
target = loads(r.text)
target = target['translateResult'][0][0]['tgt']
msgbox(msg=target, undefined.title())
|