首頁 > 後端開發 > Python教學 > Python基于有道实现英汉字典功能

Python基于有道实现英汉字典功能

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
發布: 2016-06-10 15:08:38
原創
1730 人瀏覽過

本文实例讲述了Python基于有道实现英汉字典功能的方法。分享给大家供大家参考。具体如下:

import re,urllib
aa="http://dict.youdao.com/search?tab=chn&keyfrom=dict.top&q="
print ("input q! to exit ")
while 1:
  word=raw_input(">>>")
  if word=="q!":
    exit()
  else:
    word=word.replace(' ','+')
    url=aa+word
    s=urllib.urlopen(url).read()
    comm=re.compile(r'<td class="dttitle2"><font color="#013694"><b>(.*&#63;)<\/b><\/font><\/td>')
    tem=comm.findall(s)
    com=re.compile('<td class="attributem1web">(.*&#63;)</td>',re.S|re.M|re.I)
    result=com.findall(s)
  if tem:
    for i in tem:
      temp=i.decode('utf8').encode('cp936')
      print (temp)
      print '\n'
  else:
    print ("no such word\n")

登入後複製

希望本文所述对大家的Python程序设计有所帮助。

相關標籤:
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板