Getting scrapy project settings when script is outside of root directory

前端 未结 5 2169
栀梦
栀梦 2020-12-17 17:02

I have made a Scrapy spider that can be successfully run from a script located in the root directory of the project. As I need to run multiple spiders from different project

5条回答
  •  再見小時候
    2020-12-17 17:44

    I used the OS module for this problem. The python file you are running is in one directory and your scrapy project is in a different directory. You can not simply just import the python spider and run on this python script because the current directory you are working in does not have the settings.py file or the scrapy.cfg.

    import os

    To show the current directory you are working in use the following code:

    print(os.getcwd())

    From here you are going to want to change the current directory:

    os.chdir(\path\to\spider\folder)

    Lastly, tell os which command to execute.

    os.system('scrape_file.py')

提交回复
热议问题