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