爬虫写完了,那么如何将他部署到服务器上呢?因为我们使用的是scrapy框架,所以这里使用对应的scrapyd来部署
安装 scrapyd
在服务器端安装scrapyd:1
pip install scrapyd
安装完成后,使用命令:1
scrapyd
访问http://localhost:6800/ 可以看见一个控制台
客户端安装
客户端使用:1
pip install scrapyd-client
安装完成后在工程目录下使用如下命令上传项目:1
scrapy-deploy localhost -p douban
说明 这里的localhost 是你在爬虫目录下的scrapy.cfg文件中定义的服务器名称,-p 后跟爬虫名称
1 | # Automatically created by: scrapy startproject |
执行命令的API
主要使用curl工具来对爬虫进行管控
启动
1 | curl http://localhost:6800/shchedule.json -d project=douban -d spider=xxx |
停止
1 | curl http://localhost:6800/shchedule.json -d project=douban -d job=xxxxx |
这里的jobid会在启动的时候返回,也可以通过web页面找到。