我是Python & Scrapy的初学者。我刚刚创建了一个带有多个爬虫的Scrapy项目,在运行"scrapy crawl ..“它只运行第一个爬虫。
如何在同一进程中运行所有爬行器?
提前谢谢。
发布于 2014-04-11 03:34:09
您将拥有文件中每个名为name="youspidername"的爬行器的名称。当您使用scrapy crawl yourspidername调用它时,它将只爬行那个爬行器。您必须再次发出命令,才能使用scrapy crawl youotherspidername运行另一个爬行器。
另一种方法是在同一个命令中提到所有的爬行器,比如scrapy crawl yourspidername,yourotherspidername,etc.. (较新版本的scrapy不支持这种方法)
发布于 2015-04-05 05:26:07
每个人,甚至是文档,都建议使用内部API编写一个"run script“来控制多个爬行器的启动和停止。然而,这伴随着很多警告,除非你完全正确( soon报告不工作,扭曲的反应堆不停止或太快停止等)。
在我看来,我们有一个已知的工作和支持的scrapy crawl x命令,因此一个更简单的方法是使用GNU并行来并行化。
安装后,运行(从shell)每个内核一个抓取爬虫,并假设您希望运行项目中的所有爬虫:
scrapy list | parallel --line-buffer scrapy crawl如果您只有一个内核,那么您可以尝试使用GNU并行的--jobs参数。例如,下面的代码将在每个内核上运行2个scrapy作业:
scrapy list | parallel --jobs 200% --line-buffer scrapy crawl发布于 2020-07-02 20:59:55
默认情况下,当您运行Scrapy crawl时,scrapy会为每个进程运行一个爬行器。但是,Scrapy支持使用内部API为每个进程运行多个爬行器。
有关更多信息,请查看此处:https://docs.scrapy.org/en/latest/topics/practices.html#running-multiple-spiders-in-the-same-process
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 finishedhttps://stackoverflow.com/questions/22995746
复制相似问题