python使用百度翻译进行中翻英示例

这篇文章主要介绍了python使用百度翻译进行中翻英示例,需要的朋友可以参考下

利用百度词典进行中翻英

复制代码 代码如下:

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('
',' ')
a=tran('word')#要翻译的词
ab = open('resault.txt','w')
ab.write(a)
ab.close()

以上就是python使用百度翻译进行中翻英示例的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » python