import urllib2
import re
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
def tran(word):
url='http://dict.baidu.com/s?wd={0}&tn=dict'.format(word)
print url
req=urllib2.Request(url)
resp=urllib2.urlopen(req)
resphtml=resp.read()
text = re.search(r'explain: "(.*)"',resphtml)
return text.group(1).replace('<br />',' ')
a=tran('bingo')#the word to be translated
print a.encode('gbk')
ab = open('resault.txt','w')
ab.write(a)
ab.close()
#D:\CODE\PYTHON\learning>python baiduFanyi.py
#http://dict.baidu.com/s?wd=bingo&tn=dict
#宾果游戏;太好了,好极了
Python 调用 百度翻译
最新推荐文章于 2024-12-18 09:30:38 发布