pyspider安装配置及使用
什么是 pyspider
pyspider 来源于以前做的一个垂直搜索引擎使用的爬虫后端。我们需要从200个站点(由于站点失效,不是都同时啦,同时有100+在跑吧)采集数据,并要求在5分钟内将对方网站的更新更新到库中。
所以,灵活的抓取控制是必须的。同时,由于100个站点,每天都可能会有站点失效或者改版,所以需要能够监控模板失效,以及查看抓取状态。
为了达到5分钟更新,我们使用抓取最近更新页上面的最后更新时间,以此来判断页面是否需要再次抓取。
可见,这个项目对于爬虫的监控和调度要求是非常高的。
pyspider 依赖的环境
首先需要使用 python ,至于什么版本,按个人经验来说,当然是推荐 python 2.7 了!!~因为本人曾经装的时候,被 3 坑了好久,最后不得不回退 python 才安装成功。还有,就是最好使用 32 位的 python。别问我为什么~~
最新的 pyspider 依赖包中有对 pip 版本有需求的,所以需要使用如下命令行来更新 pip 版本:
1 |
|
还依赖 PhantomJS
安装
1 |
|
在 Windows 上安装时,会发现如下错误: > Command "c:.exe -u -c
"import setuptools, tokenize;file='c:
\xiaoxin\appdata\local\temp\pip-build-ml1vkg\lxml\setup.py';f=getat
tr(tokenize, 'open',
open)(file);code=f.read().replace('', '');f.close
();exec(compile(code, file, 'exec'))" install --record
c: ata-scbd90-record-record.txt --single-version-externally- managed
--compile" failed with error code 1 in c: mp-build-ml1vkg
这时,我们需要使用到 Python Extension
Packages For Windows ,找到 lxml.whl 下载,然后使用 pip 安装即可!
1
pip install lxml.whl
如果遇到其它错误一样处理。
配置
pyspider 已经完成了大部分功能,基本上是不用配置的,当然你需要的是建立目录,不然会跑到默认目录,到时你还得找装到。
使用
在你所建的目录,直接使用 pyspider 启动即可。
提示如下: 1
2
3
4
5
6
7
8
9
10
11
12
13[W 161130 18:01:07 run:403] phantomjs not found, continue running without it.
[I 161130 18:01:10 result_worker:49] result_worker starting...
[I 161130 18:01:10 processor:208] processor starting...
[I 161130 18:01:11 tornado_fetcher:508] fetcher starting...
c:\python27\lib\site-packages\flask\exthook.py:71: ExtDeprecationWarning: Import
ing flask.ext.login is deprecated, use flask_login instead.
.format(x=modname), ExtDeprecationWarning
[I 161130 18:01:13 scheduler:569] scheduler starting...
[I 161130 18:01:13 scheduler:508] in 5m: new:0,success:0,retry:0,failed:0
[I 161130 18:01:14 scheduler:683] scheduler.xmlrpc listening on 127.0.0.1:23333
[I 161130 18:01:14 app:76] webui running on 0.0.0.0:5000
[I 161130 18:02:13 scheduler:508] in 5m: new:0,success:0,retry:0,failed:0
[I 161130 18:03:13 scheduler:508] in 5m: new:0,success:0,retry:0,failed:0
这时,你在浏览器里输入 http://localhost:5000/ 也就能看到运行效果了。