我想抓取一个包含 2 个部分的网站,但我的脚本没有我需要的那么快。
是否可以启动 2 个蜘蛛,一个用于抓取第一部分,第二个用于抓取第二部分?
我尝试有 2 个不同的类,并运行它们
scrapy crawl firstSpider
scrapy crawl secondSpider
但我认为这并不聪明。
我读了documentation of scrapyd但我不知道这是否适合我的情况。
最佳答案
我认为您正在寻找的是这样的:
import scrapy
from scrapy.crawler import CrawlerProcess
class MySpider1(scrapy.Spider):
# Your first spider definition
...
class MySpider2(scrapy.Spider):
# Your second spider definition
...
process = CrawlerProcess()
process.crawl(MySpider1)
process.crawl(MySpider2)
process.start() # the script will block here until all crawling jobs are finished
您可以阅读更多内容:running-multiple-spiders-in-the-same-process .
关于python - 在scrapy中并行运行1个网站的多个蜘蛛?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39365131/