命令行从dict.cn查单词,命令行dict.cn单词,[Python]代码Py
命令行从dict.cn查单词,命令行dict.cn单词,[Python]代码Py
[Python]代码
Python语言: 命令行从dict.cn查单词#!/usr/bin/python#coding=utf-8import urllibimport sys#import xml.dom.minidomimport re#是否输出例句eg=Truedef main(): if len(sys.argv) == 2: word = sys.argv[1] xmls = urllib.urlopen('http://dict.cn/ws.php?utf8=true&q=' + urllib.quote(word)).read() print re.search(r'<def>(?P<test>.*?)</def>', xmls, re.M|re.I|re.S|re.U).group('test') if eg: print origs=re.findall(r'<orig>(?P<orig>.*?)</orig>', xmls, re.M|re.I|re.S|re.U) trans=re.findall(r'<trans>(?P<trans>.*?)</trans>', xmls, re.M|re.I|re.S|re.U) for i in range(len(origs)): print "%d. %s"%(i+1,origs[i]) print "%s %s"%(' '*((i+1)/10+1),trans[i]) else: help()def help(): print 'usage:dict.py [word]'if __name__ == '__main__': main()
相关内容
- python url格式解析,pythonurl解析,from urlpars
- python让图片按照exif信息里的创建时间进行排序,,impo
- python beautifulsoup抓取小说练习,,学习beautifuls
- Softmax Regression,softmaxregression,from numpy i
- Heapsort,,#--coding: u
- Python脚本获取Windows窗口标题,输出到命令行,python窗口
- python urllib从远程服务器下载文件到本地,pythonurllib,u
- 随机生成彩票号码,嘿嘿,随机生成彩票号码,,xuanhao
- Python查找函数f(x)=0的根,python,''' root = r
- 编程必会之Hello World,编程helloworld,Hello#!/usr/
评论关闭