scrapy定时启动多个爬虫

最近项目需要爬取俩个不同网站的新闻内容,但是又存在同一个表,
所以就需要用到俩个Spider 指向不同的domain
这里写图片描述
但是 对于新手的我来说 只会通过

scrapy crawl human -o human.json

来启动Spider,所以每次爬取都分俩次运行,分别运行human 和nbgov

于是尝试了尝试下面的这种方式:

from scrapy import cmdline
cmdline.execute("scrapy crawl human -o human.json".split())
cmdline.execute("scrapy crawl nbgov -o nbgov.json".split())

但是 发现 它只会运行第一条 cmdline,当第一条运行结束后 第二条并不会运行

于是又花了一点时间在网上找
偶然发现一个一个文章 关于定时 爬取的

import time
import os
while True:
    print('the first spider')
    os.system("scrapy crawl human -o human.json")
    print('the second spider')
    os.system("scrapy crawl nbgov -o nbgov.json")
    time.sleep(86400)# 24hours

于是发现 这样是可以完美 定时启动 多个爬虫

猜你喜欢

转载自blog.csdn.net/qq_33042187/article/details/79023099