当前位置: 移动技术网 > IT编程>脚本编程>Python > python使用百度翻译进行中翻英示例

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

2019年03月31日  | 移动技术网IT编程  | 我要评论

深赛格股吧,娘子谷大屠杀,林志玲壁纸

利用百度词典进行中翻英

复制代码 代码如下:

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

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网