标签:
1 import urllib.request # 对服务器的 请求 发出 代理 安全 等方面 2 3 import easygui as g 4 5 import json 6 7 import urllib.parse 8 9 if g.ccbox(‘是否进入翻译系统?‘,‘小猿翻译‘,choices=(‘是‘,‘否‘)): 10 str1=g.enterbox(msg=‘请输入翻译内容‘,title=‘小猿翻译‘,default=‘我爱蔡伟伟(这里是默认输入)‘) 11 else: 12 g.msgbox(‘您已退出‘) 13 14 count=1 15 16 while True: 17 18 if count==1: 19 count += 1 20 else: 21 str1=g.enterbox(msg=‘请输入翻译内容‘,title=‘小猿翻译‘,default=‘我还是很爱蔡伟伟(这里是默认输入)‘) 22 23 url=‘http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&smartresult=ugc&sessionFrom=https://www.baidu.com/link‘ 24 25 date={} 26 27 date[‘type‘] = ‘AUTO‘ 28 29 date[‘i‘] = str1 30 31 date[‘doctype‘] = ‘json‘ 32 33 date[‘xmlVersion‘] = ‘1.8‘ 34 35 date[‘keyfrom‘] = ‘fanyi.web‘ 36 37 date[‘ue‘] = ‘UTF-8‘ 38 39 date[‘action‘] = ‘FY_BY_CLICKBUTTON‘ 40 41 date[‘typoResult‘] = ‘true‘ 42 43 date = urllib.parse.urlencode(date).encode(‘utf-8‘) 44 45 response = urllib.request.urlopen(url,date) 46 47 html = response.read().decode(‘utf-8‘) 48 49 html=json.loads(html) 50 51 str1=‘翻译为: ‘ + html[‘translateResult‘][0][0][‘tgt‘] 52 53 if g.ccbox(str1,choices=(‘继续‘,‘退出‘)): 54 pass 55 else: 56 break
标签:
原文地址:http://www.cnblogs.com/A-FM/p/5687754.html