0

I was wondering what is the best way to run spiders from another python script. My scrapy project consist of 4 different spiders, all of them create files that help the other spiders work and some of them have to read some files to work. That part is already done but individually (running the spiders separate from the console).

How can I, for example, do something like this

if (productToSearchIsBlue):

    #Make one spider crawl

else:

    #Make another spider crawl

My final plan is to upload the full program to the cloud and make it run automatically, can this be done?

I found some answers to this question but they were pretty old, probably for another version of scrapy.

0

1 Answer 1

2

Assuming you have everything else set up correctly, here is a trivial example as per the documentation.

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


process = CrawlerProcess(get_project_settings())

productToSearchIsBlue = False

if productToSearchIsBlue:
    # Make one spider crawl
    process.crawl('spider-one')
else:
    # Make another spider crawl
    process.crawl('spider-two')

process.start()

You can then run this on a cloud server. But I cannot answer whether this is the optimal solution for the problem you are trying to solve.

Sign up to request clarification or add additional context in comments.

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.