用 Python 3 写的命令行百度词典
今天是第二天自己看关于Python了,看见一个Python2写的百度词典,我也用Python 3 写了一个。真的很小巧,呵呵,很好的语言。
不知道怎么上传代码格式的,就上传文本了:
# -*- coding: utf8 -*-
import urllib.parse
import urllib.request
def search(word):
#word = input("输入你要查询的单词:")
url="http://m.baidu.com/s?word="+word+"&ssid=0&from=0&bd_page_type=1&uid=frontui_1273397350_2416&mark=3"
s = (urllib.request.urlopen(url).read()).decode("UTF-8")
p=s[s.find("<div>")+5:s.find("</div>")-12]
q=p.split("<br/>")
for i in range(0,len(q)):
q[i]=q[i][0:(q[i].find("[<img"))]
q[i]=q[i][0:(q[i].find("<img"))]
print(q[i])
search(input("输入你要查询的单词:"))
search(input("输入你要查询的单词:"))
22:27:40
相关文档:
需要先安装libxml2-devel libxslt-devel这两个rpm包,如果使用非root用户安装,可以下载libxml2和libxslt的源代码进行安装。 libxml2-devel、libxslt-devel装好后,解压lxml的包,切换到这个包的路径。
加入CFLAGS进行编译和安装,在shell下依次输入如下命令: CFLAGS=-I/usr/include/libxml2:/usr/include/libxslt/ ......
Install Python Eric IDE
1 Download following things
1) Python3.1
2) PyQt for python 3.1
(http://www.riverbankcomputing.co.uk/software/pyqt/download) I am using
PyQt-Py3.1-gpl-4.7.3-2.exe
3) Eric5 IDE
(http://eric-ide.python-projects.org/eric-download.html)
2 ......
队列:
与堆栈类似,通过python的列表类型来实现,参考 help(list)
shoplist=['apple','mango','carrot','banana']
print 'I have',len(shoplist),'items to purchase'
print 'these items are:'
for item in shoplist:
print item,
shoplist.append('rice')
print 'my shopping list is now', shoplist
shoplist. ......
#from pp3e Chapter 9.3
#############################################################################
# popup three new window, with style
# destroy() kills one window, quit() kills all windows and app; top-level
# windows have title, icon, iconify/deiconify and protocol for wm events;
# there ......