知道创宇爬虫
- args_parser.py 处理命令行参数
- database.py 数据库相关操作
- spider.py 爬虫主体
在命令行中运行,结果如下
python spider.py -u http:www.baidu.com -d 2 --dbfile baidu.db
使用urlparse中的urljoin来提取页面内的相对链接
- log_setting.py 配置logging
- my_threadpool.py 线程池实现
测试页面: https://docs.python.org/2/library/urlparse.html
测试命令: python .\spider.py -u https://docs.python.org/2/library/urlparse.html -d 2 --dbfile python.db --thread 10 -f python.log -l 5
从该页面提取的出的链接存放在result.txt中,经过比对,正确找出了页面中的相对链接和以http开头的链接。
测试命令:python .\spider.py -u https://docs.python.org/2/library/urlparse .html -d 2 --dbfile python.db --thread 5 -f python.log -l 5 --keyword python --testself
结果如下:
解决Windows命令行中文参数的编码问题, 大概就是不用windows了吧~