Scrapy順序執行多個爬蟲

Scrapy順序執行多個爬蟲

使用subprocess按照順序執行多個爬蟲,新建一個start.py文件,輸入一下內容,

def crawl_work():
    subprocess.Popen('scrapy crawl spider1', shell=True).wait()
    subprocess.Popen('scrapy crawl spider2', shell=True).wait()
    subprocess.Popen('scrapy crawl spider3', shell=True).wait()
    subprocess.Popen('scrapy crawl spider4', shell=True).wait()
if __name__ == '__main__':
    crawl_work()

需要注意的是,如果你是用shell文件+crontab定時運行爬蟲程序的話,需要在shell
腳本中先定位到scrapy項目中再運行,比如:

cd /home/program/YourProject/;/usr/bin/python ./start.py
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章