码迷,mamicode.com
首页 > Windows程序 > 详细

调用网易有道词典api

时间:2015-10-23 21:27:17      阅读:406      评论:0      收藏:0      [点我收藏+]

标签:

# -*- coding: utf-8 -*-
#python 27
#xiaodeng
#调用网易有道词典api

import urllib import json class Youdao(): def __init__(self,word): self.url=‘http://fanyi.youdao.com/openapi.do‘ #url、key、keyfrom都是固定的值,所以采用这种方式赋值 self.key=‘929705525‘ self.keyfrom=‘pythonxiaodeng‘ self.word=word def getTranslation(self): data={‘keyfrom‘:self.keyfrom, ‘key‘:self.key, ‘type‘:‘data‘, ‘doctype‘:‘json‘, ‘version‘:‘1.1‘, ‘q‘:self.word} #encode data=urllib.urlencode(data) #print data #keyfrom=pythonxiaodeng&doctype=json&q=student&version=1.1&key=929705525&type=data url=self.url+‘?‘+data #链接url和参数dict html=urllib.urlopen(url).read() html=json.loads(html) return html #调用 youdao=Youdao(‘student‘) result=youdao.getTranslation() for key in result: print key

 

调用网易有道词典api

标签:

原文地址:http://www.cnblogs.com/dengyg200891/p/4905643.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!