Python基于有道实现英汉字典功能,python英汉字典
Python基于有道实现英汉字典功能,python英汉字典
本文实例讲述了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>(.*?)<\/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")
希望本文所述对大家的Python程序设计有所帮助。
相关内容
- Python实现模拟登录及表单提交的方法,python表单
- Python中Django框架利用url来控制登录的方法,pythondjango
- Python基于动态规划算法计算单词距离,python算法
- Python计算已经过去多少个周末的方法,python已经过去
- 详解Python的Django框架中的中间件,pythondjango
- Python字符串转换成浮点数函数分享,python点数
- 通过mod_python配置运行在Apache上的Django框架,mod_pythond
- 在Django的上下文中设置变量的方法,django上下文
- Python简单调用MySQL存储过程并获得返回值的方法,pyth
- 在Django框架中运行Python应用全攻略,djangopython
评论关闭