粗糙的中间件顺序 [英] Scrapy middleware order

查看:84
本文介绍了粗糙的中间件顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Scrapy 文档说:

Scrapy documentation says :

第一个 中间件更接近 引擎,最后一个更近 到下载器.

the first middleware is the one closer to the engine and the last is the one closer to the downloader.

决定要分配给哪个订单 您的中间件 DOWNLOADER_MIDDLEWARES_BASE设置 然后根据位置选择一个值 您要插入中间件.这 顺序很重要,因为每个 中间件执行不同的操作 您的中间件可能取决于 一些先前的(或后续的) 正在应用中间件

To decide which order to assign to your middleware see the DOWNLOADER_MIDDLEWARES_BASE setting and pick a value according to where you want to insert the middleware. The order does matter because each middleware performs a different action and your middleware could depend on some previous (or subsequent) middleware being applied

由此我不能完全清楚是否更高的值会导致中间件 首先被执行,反之亦然.

I'm not entirely clear from this whether a higher value would result in a middleware getting executed first or vice versa.

例如

'myproject.middlewares.MW1': 543,
'myproject.middlewares.MW2': 542,

问题:

  1. 其中哪些将首先执行?我的审判说MW2将是第一个.
  2. 订单的有效范围是多少? 0-999吗?

推荐答案

  1. 其中哪些将首先执行?我的审判说MW2将是第一个.

引用文档时

第一个中间件是离引擎更近的中间件,最后一个是离下载器更近的中间件.

the first middleware is the one closer to the engine and the last is the one closer to the downloader.

因此,值542的下载器中间件在值543的中间件之前执行.这意味着首先

So downloader middleware with value of 542 is executed before the middleware with value 543. It means first myproject.middlewares.MW1.process_request(request, spider) is called, and after it altered (if needed) the request, it is passed to the next downloader middleware.

  1. 订单的有效范围是多少? 0-999吗?

该值为整数.

更新:

查看体系结构.

此外,完整的 quote :

DOWNLOADER_MIDDLEWARES设置与 在Scrapy中定义的DOWNLOADER_MIDDLEWARES_BASE设置(并不意味着 被覆盖),然后按顺序排序以进行最终排序 启用的中间件列表:第一个中间件更接近 引擎,最后一个是最接近下载器的引擎.

The DOWNLOADER_MIDDLEWARES setting is merged with the DOWNLOADER_MIDDLEWARES_BASE setting defined in Scrapy (and not meant to be overridden) and then sorted by order to get the final sorted list of enabled middlewares: the first middleware is the one closer to the engine and the last is the one closer to the downloader.

因此,由于值是整数,因此它们具有Python整数范围.

So, as the values are integers, they have range of Python integers.

这篇关于粗糙的中间件顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆