celery 调用scrapy

Posted walkonmars

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了celery 调用scrapy相关的知识,希望对你有一定的参考价值。

  我的环境: celery 3.1.25 python 3.6.9 window10

 

celery tasks 代码如下,其中 QuotesSpider 是我的scrapy项目爬虫类名称

from celery_app import app
from scrapy.crawler import CrawlerProcess
from scrapy.utils.project import get_project_settings
from tutorial.spiders.quotes import QuotesSpider

def crawl_run():
scope = ‘all‘
process = CrawlerProcess(settings=get_project_settings())
process.crawl(QuotesSpider, scope)
process.start()
process.join()

@app.task(queue=‘default‘)
def execute_task():
return crawl_run()

以上是关于celery 调用scrapy的主要内容,如果未能解决你的问题,请参考以下文章