手机
当前位置:查字典教程网 >脚本专栏 >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的常见命令注入威胁

Python3基础之基本运算符概述

python二叉树的实现实例

python单链表实现代码实例

Python设计模式之单例模式实例

python二叉树遍历的实现方法

Python 文件操作实现代码

python 实现插入排序算法

精品推荐
分类导航