kunsoft

Python就是爽啊,用来抓网页信息是再合适不过了。今天结合小甲鱼的视频做了一个简易翻译工具,大牛勿喷,仅供娱乐!^_^

主要用到的模块是json和easyGUI,结合网易有道翻译的网页制作而成。效果还可以。

# Powered By KunSoft
# 2015年2月27日
from urllib.request import *
from urllib.parse import *
import easygui as g
import json

while True:
    content = g.enterbox(msg=\'输入要翻译的内容\', title=\'简易翻译器\')  #显示GUI界面,读入输入信息
    if content == None:   #如果点击关闭按钮,退出程序
        exit(0)
    #有道词典翻译链接
    url = \'http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&smartresult=ugc&sessionFrom=http://www.youdao.com/\'
    #上传信息并编码为utf-8格式
    data = {\'type\':\'AUTO\', \'i\':content, \'doctype\':\'json\', \'xmlVersion\':\'1.6\', \'keyfrom\':\'fanyi.web\', \'ue\':\'UTF-8\', \'typoResult\':\'true\'}
    data = urlencode(data).encode(\'utf-8\')
    #打开链接,获取结果,将json格式保存
    response = urlopen(url, data)
    html = response.read().decode(\'utf-8\')
    html = json.loads(html)
    #输出结果并进入下一次翻译
    g.msgbox(msg = html[\'translateResult\'][0][0][\'tgt\'], title=\'翻译结果\')





分类:

技术点:

相关文章:

  • 2021-07-27
  • 2022-01-02
  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
  • 2021-07-24
  • 2021-05-03
  • 2021-06-23
猜你喜欢
  • 2021-12-11
  • 2021-09-18
  • 2021-10-21
  • 2022-01-02
  • 2022-01-21
  • 2021-11-25
  • 2021-11-20
相关资源
相似解决方案