html连接有道词典api,调用网易有道词典api

# -*- 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=''

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连接有道词典api)