0

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 Answers 2

1

The problem was with path. I had to add:

import os
os.chdir(r'project_path')
Sign up to request clarification or add additional context in comments.

Comments

1

I do this to run my spider.

import os
import subprocess

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.