手机
当前位置:查字典教程网 >脚本专栏 >python >python使用百度翻译进行中翻英示例
python使用百度翻译进行中翻英示例
摘要:利用百度词典进行中翻英复制代码代码如下:importurllib2importreimportsysreload(sys)sys.setde...

利用百度词典进行中翻英

复制代码 代码如下:

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()

【python使用百度翻译进行中翻英示例】相关文章:

python的urllib模块显示下载进度示例

Python pass 语句使用示例

python定时器使用示例分享

python33 urllib2使用方法细节讲解

python在命令行下使用google翻译(带语音)

python学习手册中的python多态示例代码

python中mechanize库的简单使用示例

python多线程扫描端口示例

python thread 并发且顺序运行示例

python异步任务队列示例

精品推荐
分类导航