Python使用Youdao API 的有道词典小程序
2014-02-15 16:56
232 查看
先去有道官网申请API key,很容易申请到的.
使用方法:输入要翻译的中文或者英语,打印翻译结果,输入quit,程序结束
使用方法:输入要翻译的中文或者英语,打印翻译结果,输入quit,程序结束
#!/usr/bin/env python #coding:utf-8 #By eathings import urllib2 import re import json class Youdao: def __init__(self): self.url = 'http://fanyi.youdao.com/openapi.do' self.key = 'API key' #有道API key self.keyfrom = 'keyfrom' #有道keyfrom def get_translation(self,words): url = self.url + '?keyfrom=' + self.keyfrom + '&key='+self.key + '&type=data&doctype=json&version=1.1&q=' + words result = urllib2.urlopen(url).read() json_result = json.loads(result) json_result = json_result["translation"] for i in json_result: print i youdao = Youdao() while True: msg=raw_input() if msg == 'quit': break youdao.get_translation(msg)
相关文章推荐
- 使用PyInstaller打包Python程序
- Python程序中使用SQLAlchemy时出现乱码的解决方案
- Python使用wxPython、py2exe编写桌面程序
- 使用Python+tkinter编写电脑桌面放大镜程序
- VS2013 C#WinForm程序构造界面拖动控件NumericUpDown时"未响应“是有道词典惹的祸
- 使用python+hadoop-streaming编写hadoop处理程序
- windows下使用批处理文件调用python程序
- python使用PyCharm调试Scrapy程序
- 自己使用总结Python程序代码片段
- 在Python程序中操作文件之isatty()方法的使用教程
- 使用python编写udp协议的ping程序
- python cgi ajax - 使用CGIHTTPServer实现一个ajax程序
- 使用Python实现Hadoop MapReduce程序
- 使用Apache+mod_wsgi部署webpy等python程序
- Windows 平台上的使用 Python 语言实现 appium 自动化程序环境配置
- 使用PyQt来编写第一个Python GUI程序
- python 学习笔记 11 -- 使用参数使你的程序变得更性感
- 使用IDAPYTHON跟踪程序执行路径-未加壳
- 使用 Notepad++ 编辑运行 Python 程序
- 有道词典使用时不断最小化还原闪烁的解决办法