|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import easygui as e
import sys
import urllib.request
import urllib.parse
import json
import time
def result(msg):
title = "翻译结果"
if e.ccbox(msg,title,choices=('继续翻译','结束翻译')):
pass
else:
sys.exit(0)
while 1:
password = e.passwordbox(msg='请输入密码',title='密码输入')
if password == '19991220':
while 1:
content = e.enterbox(msg='请输入需要翻译的内容(输入“!”结束翻译):',title='输入内容',strip=False)
if content == '!'or content == '!' or content == None:
e.msgbox(msg='翻译结束!!!',title='翻译结束',ok_button='离开')
sys.exit(0)
if content == '':
e.msgbox(msg='输入为空!!!',title='输入有误',ok_button='重新输入')
pass
else:
url = 'http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule'
head = {}
head['User-Agent'] = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36'
data = {}
data['type'] = 'zh-CHS2ja'
data['from'] = 'zh-CHS'
data['to'] = 'ja'
data['i'] = content
data['smartresult'] = 'dict'
data['client'] = 'fanyideskweb'
data['salt'] = '16087724367165'
data['sign'] = '7f099a3436de63d8c06ddaebce8cced0'
data['lts'] = '1608772436716'
data['bv'] = 'acc97416ef67184f42e5a4a03c3d52ab'
data['doctype'] = 'json'
data['version'] = '2.1'
data['keyfrom'] = 'fanyi.web'
data['action'] = 'FY_BY_CLICKBUTTION'
data = urllib.parse.urlencode(data).encode('utf-8')
req = urllib.request.Request(url, data, head)
response = urllib.request.urlopen(url, data)
html = response.read().decode('utf-8')
target = json.loads(html)
target = target['translateResult'][0][0]['tgt']
msg = '翻译出的结果是:' + target
#e.msgbox(msg='翻译的结果是:target',title='翻译结果',ok_button="继续翻译!")
result(msg)
elif password == None:
break
else:
if e.msgbox(msg='密码错误,请重新输入!',title='密码错误',ok_button='重新输入'):
pass
else:
break
|
|