时间:2021-07-01 10:21:17 帮助过:169人阅读
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()