0
点赞
收藏
分享

微信扫一扫

scrapy项目部署

GhostInMatrix 2022-04-05 阅读 78
python

服务启动

选择一台主机当做服务器,安装并启动 scrapyd 服务

​服务端:pip install scrapyd

客户端:pip install scrapyd-client

启动服务:scrapyd,可以打开网址表示服务启动成功

 

项目部署

1.编辑需要部署的项目的scrapy.cfg文件,然后在该目录下执行以下命令进行项目部署

2.scrapyd-deploy 部署名(配置文件中设置的名称) -p 项目名称

eg:scrapyd-deploy abcd -p  crawl_spider

3.部署成功后刷新页面

 

 执行任务

启动项目:

方式一:

curl http://localhost:6800/schedule.json -d project=项目名 -d spider=爬虫名

关闭项目:

curl http://localhost:6800/cancel.json -d project=项目名 -d job=项目的jobid

删除项目:

curl http://localhost:6800/delproject.json -d project=爬虫项目名称

方式二:

import requests

# 启动爬虫
url = 'http://localhost:6800/schedule.json'
data = {
	'project': 项目名,
	'spider': 爬虫名,
}
resp = requests.post(url, data=data)

# 停止爬虫
url = 'http://localhost:6800/cancel.json'
data = {
	'project': 项目名,
	'job': 启动爬虫时返回的jobid,
}
resp = requests.post(url, data=data)
举报

相关推荐

Django 项目部署

Windows项目部署

Flask项目部署

Linux项目部署

前端项目部署

Docker项目部署

0 条评论