手机
当前位置:查字典教程网 >脚本专栏 >python >Python基于有道实现英汉字典功能
Python基于有道实现英汉字典功能
摘要:本文实例讲述了Python基于有道实现英汉字典功能的方法。分享给大家供大家参考。具体如下:importre,urllibaa="http:/...

本文实例讲述了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><font color="#013694"><b>(.*?)</b></font></td>') tem=comm.findall(s) com=re.compile('<td>(.*?)</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 wordn")

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

【Python基于有道实现英汉字典功能】相关文章:

Python Trie树实现字典排序

python连接池实现示例程序

python二叉树遍历的实现方法

python创建和使用字典实例详解

python单链表实现代码实例

python二叉树的实现实例

Python去掉字符串中空格的方法

使用python实现strcmp函数功能示例

python两种遍历字典(dict)的方法比较

python绘图库Matplotlib的安装

精品推荐
分类导航