request.meta vs class 属性 scrapy

request.meta vs class attributes scrapy

为了在scrapy中处理回调之间的数据,可以定义class属性:

def __init__(self, *args, **kwargs):
    self.my_var = 1 

并使用:

self.my_var

而不是:

request.meta['my_var'] = 1

request.meta is the perfect and reliable way to pass meta information tied to a specific request. For example, if you parse basic product information from the product list page and want to pass along this information to the product details page callback - request.meta is the perfect solution. meta also has a number of special keys 允许控制特定请求的行为。