0
votes

I have a scrapy project with two spiders. Also I created test.py (in this scrapy project) to crawl spiders

code :

from scrapy.crawler import CrawlerProcess
from scrapy.utils.project import get_project_settings

process = CrawlerProcess(get_project_settings())

process.crawl('nameofspider1', domain='domain')
process.crawl('nameofspider2', domain='domain')

process.start() 

and it works fine.

The problem is when I want to run this script (test.py) from another python script, then I got

KeyError: 'Spider not found: nameofspider1'

The code of the second python script:

import os

os.system('python C:\Users\Adam\nameofproject\test.py')

Thanks for all replies.

2

2 Answers

1
votes

The problem was with path. I had to add:

import os
os.chdir(r'project_path')
0
votes

I do this to run my spider.

import os
import subprocess

os.chdir('projectname')
subprocess.call(
    ['scrapy', 'crawl', 'spidername']
)