1. 程式人生 > >如何實現多個爬蟲迴圈順序爬取

如何實現多個爬蟲迴圈順序爬取

首先設定一個迴圈,接著為每一個爬蟲設定一個定時器,讓每一個爬蟲爬蟲一段時間,再執行下一個爬蟲即可。具體程式碼如下,此處設定每一個爬蟲執行3600秒

import os

while True:
    os.system("scrapy crawl xinhuanet -s CLOSESPIDER_TIMEOUT=3600")  # 新華網
    os.system("scrapy crawl money163 -s CLOSESPIDER_TIMEOUT=3600")  # 網易財經
    os.system("scrapy crawl ccstock -s CLOSESPIDER_TIMEOUT=3600")  # 證券日報
    os.system("scrapy crawl cs -s CLOSESPIDER_TIMEOUT=3600")  # 中證網
    os.system("scrapy crawl p5w -s CLOSESPIDER_TIMEOUT=3600")  # 全景網
    os.system("scrapy crawl ztcj -s CLOSESPIDER_TIMEOUT=3600")  # 智通財經
    os.system("scrapy crawl huanqiu_finance -s CLOSESPIDER_TIMEOUT=3600")  # 環球財經