Scrapy - Crawl 蜘蛛的流程
Scrapy - flow of the Crawl spider
我很难搞清楚 Scrapy 是如何工作的(或者我需要如何使用它)。
这个问题有点宽泛,更多的是为了理解。
我设置了一个 CrawlSpider 并输入了 6 个起始 url。
从那些(在每个开始 url 上抓取 24 个项目)我预计大约 144 行最终会出现在我的数据库中,但我现在只有 18 行。
所以我正在使用
def parse_start_url(self, response):
暂时避免规则的复杂化。
现在 Scrapy 应该获取这 6 个 url 并抓取它们,然后处理这些页面上的项目。
但相反,它似乎接受了这 6 个网址,然后检查这些页面上的每个 link,然后首先关注那些 link——这可能吗?
Scrapy 是否只需要 URL 1,扫描所有 link 并遵循所有允许的内容?
什么时候需要 URL 2?
您可以在 official documentation page 中找到您的答案,但为了完整起见,我将其粘贴在这里:
By default, Scrapy uses a LIFO queue for storing pending requests,
which basically means that it crawls in DFO order. This order is more
convenient in most cases. If you do want to crawl in true BFO order,
you can do it by setting the following settings:
DEPTH_PRIORITY = 1
SCHEDULER_DISK_QUEUE = 'scrapy.squeues.PickleFifoDiskQueue'
SCHEDULER_MEMORY_QUEUE = 'scrapy.squeues.FifoMemoryQueue'
注:
您描述爬网顺序的方式通常称为 DFS (depth-first search) or BFS (广度优先搜索)。 Scrapy使用了DFO和BFO('O'是为了'order',但意思是一样的)。
我很难搞清楚 Scrapy 是如何工作的(或者我需要如何使用它)。 这个问题有点宽泛,更多的是为了理解。
我设置了一个 CrawlSpider 并输入了 6 个起始 url。
从那些(在每个开始 url 上抓取 24 个项目)我预计大约 144 行最终会出现在我的数据库中,但我现在只有 18 行。
所以我正在使用
def parse_start_url(self, response):
暂时避免规则的复杂化。
现在 Scrapy 应该获取这 6 个 url 并抓取它们,然后处理这些页面上的项目。
但相反,它似乎接受了这 6 个网址,然后检查这些页面上的每个 link,然后首先关注那些 link——这可能吗?
Scrapy 是否只需要 URL 1,扫描所有 link 并遵循所有允许的内容?
什么时候需要 URL 2?
您可以在 official documentation page 中找到您的答案,但为了完整起见,我将其粘贴在这里:
By default, Scrapy uses a LIFO queue for storing pending requests, which basically means that it crawls in DFO order. This order is more convenient in most cases. If you do want to crawl in true BFO order, you can do it by setting the following settings:
DEPTH_PRIORITY = 1
SCHEDULER_DISK_QUEUE = 'scrapy.squeues.PickleFifoDiskQueue'
SCHEDULER_MEMORY_QUEUE = 'scrapy.squeues.FifoMemoryQueue'
注: 您描述爬网顺序的方式通常称为 DFS (depth-first search) or BFS (广度优先搜索)。 Scrapy使用了DFO和BFO('O'是为了'order',但意思是一样的)。