代码如下:
import urllib2
import re
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
def tran(word):
url='http://dict.baidu测试数据/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使用百度翻译进行中翻英示例的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did87544