代碼在這里,注釋夠詳細,應該很容看懂吧。(注,程序里面有坑。。。直接用,不看代碼小心中招,嘿嘿。。。)
https://github.com/5crat/spider.py
關於該爬蟲
程序運行示例:
Spider.py -u url -d depth
Url,depth 為必需參數,其他為可選參數,日志文件默認當前目錄,名字:spider.log,日志等級默 認為3。數據庫為:data.sql,也是當前目錄。
關鍵字是匹配源碼中標簽<meta>的content屬性的值
自檢模塊只是檢查網絡連接,和數據庫連接。
winXP sp3 和 ubuntu12.10測試爬取www.baidu.com兩級深度均能正常運行
目前自知的缺點:
對於命令參數,沒有仔細檢查分析,如:spider -u s -d 2程序一樣會運行,雖然這樣不對。
主要參考:
Python爬蟲
http://bbs.chinaunix.net/thread-3689276-1-1.html
對Python線程池進行詳細說明
http://developer.51cto.com/art/201002/185290.htm
BeautifulSoup學習筆記
http://pqcc.iteye.com/blog/627481
python之sqlite3使用詳解
http://anony3721.blog.163.com/blog/static/5119742010716104442536/
Python模塊學習
http://www.cnblogs.com/captain_jack/archive/2011/01/11/1933366.html