# fileName : dict.py
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>(.*?)<\/b><\/font><\/td>')
tem=comm.findall(s)
com=re.compile('<td class="attributem1web">(.*?)</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")
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>(.*?)<\/b><\/font><\/td>')
tem=comm.findall(s)
com=re.compile('<td class="attributem1web">(.*?)</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")
有道词典API爬虫
本篇博客介绍了一个简单的Python脚本,该脚本利用正则表达式从有道词典网站抓取英文单词的释义。通过用户输入单词,脚本能够访问有道词典并解析返回的HTML内容,提取所需词汇的解释。
2403

被折叠的 条评论
为什么被折叠?



