您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

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

2024/2/23 18:47:22发布15次查看
利用百度词典进行中翻英
复制代码 代码如下:
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()
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product