scrapy部署运行测试

安装scrapy

pip install scrapyd
pip install scrapyd-client

安装好后输入scrapyd,结果如下
在这里插入图片描述

部署scrapy爬虫,先配置好需要部署的爬虫的scrapy.cfg文件

原先

# Automatically created by: scrapy startproject
#
# For more information about the [deploy] section see:
# https://scrapyd.readthedocs.io/en/latest/deploy.html

[settings]
default = biqu.settings

[deploy]
#url = http://localhost:6800/
project = biquge

部署后

# Automatically created by: scrapy startproject
#
# For more information about the [deploy] section see:
# https://scrapyd.readthedocs.io/en/latest/deploy.html

[settings]
default = biquge.settings

[deploy:bq] #在deploy加上:部署名
url = http://localhost:6800/   #把url前面的#去掉
project = biquge

再打开一个cmd路径切换到要部署的scrapy爬虫文件下

执行

scrapyd-deploy bq -p biquge

输出
在这里插入图片描述
网页查看
在这里插入图片描述

运行

格式

curl http://localhost:6800/schedule.json -d project=default -d spider=somespider

运行部署好的爬虫

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

执行后
在这里插入图片描述

在这里插入图片描述

停止

curl http://localhost:6800/schedule.json -d project=biquge -d job=87384812df5311ec8f257470fd3a1483  
#job爬虫运行返回的jobid

py文件执行部署的爬虫,运行,停止,删除

import requests
def open():
    url="http://localhost:6800/schedule.json"
    data={
        'project':'biquge',
        'spider':'biquge_spider'
    }
    r=requests.post(url,data=data)
    text=r.json()
    print(text)
def close():
    url="http://localhost:6800/schedule.json"
    data={
        'project':'biquge',
        'job':'87384812df5311ec8f257470fd3a1483'
    }
    r=requests.post(url,data=data)
    text=r.json()
    print(text)
def delete():
    # curl http://localhost:6800/delproject.json -d project=biquge
    url="http://localhost:6800/delproject.json"
    data={
         "project":"biquge"
    }
    r=requests.post(url,data=data)
    # print(r.json())
if __name__ == '__main__':
    delete()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值