91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

資源簡介

自己利用空閑時間寫的一款再dos下運行的簡單搜索引擎,可以再自己給定的網頁范圍內查找信息,并且下載指定網頁上的內容。內中包含簡單的工程文檔,代碼還算規范,所以不需要太多注釋就基本能看懂。學習python沒多久的同學可以看一下,對于學習python能夠給出一定的啟發

資源截圖

代碼片段和文件信息

#-*-?coding:utf-8?-*-

import?urllib
import?os
import?re
import?HtmlToText
import?SearchEngineLog

class?SearchEngine:
def?__init__(self):
self.lstSearchedItems? =?[]
self.lstKeywords? =?[]
self.strKeywords? =?‘‘
self.iItemsEachPage? =?10
self.iCurrentPage???????=?1
self.strConfigFile? =?‘./config.ini‘
self.log? =?SearchEngineLog.SearchEngineLog()
self.initCommand()
self.readConfigFile()
self.headWidth =?80
self.strCurrentSite =?‘‘

def?initCommand(self):
self.cmdCommand? =?‘command‘
self.cmdKeywords? =?‘keywords‘
self.cmdQuit? =?‘q‘
self.cmdBack? =?‘b‘
self.cmdNextPage? =?‘n‘
self.cmdPrevPage? =?‘l‘
self.cmdRefresh? =?‘r‘
self.cmdSavePage? =?‘s‘

def?work(self):
while?True:
self.mainSurface(‘‘)
self.useKeywordsInput()

def?mainSurface(selfinfo):
self.strSurface?=?‘MAIN_SURFACE‘
os.system(‘cls‘)
print?‘=‘?*?self.headWidth
print?‘?‘?*?((?self.headWidth?-?len(‘SEARCH?ENGINE‘)?)/2)?‘SEARCH?ENGINE‘
print?‘?‘?*?((?self.headWidth?-?len(info)?)/2)?info
print?‘=‘?*?self.headWidth

def?searchSurface(selfinfo):
self.strSurface?=?‘SEARCH_SURFACE‘
os.system(‘cls‘)
print?‘=‘?*?self.headWidth
print?‘The?search?result?of?:??‘??self.strKeywords
print?‘-‘?*?self.headWidth
if?len(self.lstSearchedItems)?==?0:
print?‘Cannot?find?“%s“!‘?%?self.strKeywords
else?:
iCount?=?0
for?item?in?self.lstSearchedItems:
if?item[0]?>?(self.iCurrentPage-1)*self.iItemsEachPage?and?item[0]?<=?self.iItemsEachPage?*?self.iCurrentPage:
iCount?=?iCount?+?1
print?‘%d??%s‘?%?(iCountitem[1])
print?‘??‘item[2]
print?‘‘
print?‘=‘?*?self.headWidth
print?‘Current?page:?%d/%d‘?%?(self.iCurrentPagelen(self.lstSearchedItems)/self.iItemsEachPage?+?1)

def?downWebsite(selfurlpath):
print?urlpath?‘is?downloading...‘
####創建存放網頁內容的文件夾
regex?=?r‘(.*//www.)(.*)(.com|.cn|.net)‘
res?=?re.match(regexurlpath)
saveFolder?=?res.group(2)
cmd?=?‘md?‘?+?saveFolder
os.system(cmd)
textFilePath?=?saveFolder+?‘/‘?+res.group(2)+‘.html‘
####下載文本網頁
print?‘downloading?the?html?file...‘
webContex?=?‘‘
try:
ul?=?urllib.urlopen(urlpath)
webContext?=?ul.read()
ul.close()
except?Exceptionerr:
print?‘Cannot?open?%splease?check?your?network!‘?%?urlpath
self.log.errorLog(‘download?website?“%s“?fail‘?%?urlpath)
exit(-1)
try:
file?=?open(textFilePath‘w‘)
file.write(webContext)
file.close()
except?Exceptionerr:
print?‘Create?file?“%s“?fail!‘?%?textFilePath
self.log.errorLog(‘create?file?“%s“?fail‘?%?textFilePath)
####下載圖片
print?‘downloading?pictures...‘
regex?=?r‘(http:.+?\.png|http:.+?\.jpg|http:.+?\.jpeg|http:.+?\.gif|http:.+?\.bmp)‘
lstPictures?=?re.findall(regexwebContext)
for?picPath?in?lstPictures:
regex?=?r‘(.*)(<|>|“)(.*)‘
if?re.match(regexpicPath):?continue
regex?=?r‘(.*)(/.*)‘
picName

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2016-12-28?17:25??SearchEngine\
?????文件???????49374??2016-12-28?17:12??SearchEngine\Capture.PNG
?????文件???????45274??2016-12-28?17:12??SearchEngine\Capture1.PNG
?????文件???????61643??2016-12-28?17:13??SearchEngine\Capture2.PNG
?????文件???????34963??2016-12-28?17:15??SearchEngine\Capture3.PNG
?????文件???????33687??2016-12-28?17:20??SearchEngine\Capture4.PNG
?????文件?????????105??2016-12-28?17:14??SearchEngine\config.ini
?????文件????????3873??2016-12-28?16:58??SearchEngine\document.txt
?????文件????????2673??2016-12-28?17:20??SearchEngine\SearchEngine.log
?????文件????????8351??2016-12-28?17:19??SearchEngine\SearchEngine.py
?????文件???????????0??2016-12-28?16:54??SearchEngine\SearchEngine.pyc
?????文件????????1757??2016-12-28?15:35??SearchEngine\SearchEngineLog.py
?????文件????????3525??2016-12-28?15:36??SearchEngine\SearchEngineLog.pyc

評論

共有 條評論