簡體   English   中英

抓取項目管道中蜘蛛的訪問響應

[英]Access response from spider in items pipeline in scrapy

我像蜘蛛

class ProductsSpider(scrapy.Spider):
    name = "products"
    allowed_domains = ["example.com"]
    start_urls = [
        'http://example.com/url'
    ]

    def parse(self, response):

我有一個這樣的管道課程

class ProductsDataPipeline(object):
    """ Item pipeline for products data crawler """

    def process_item(self, item, spider):   
        return item

但我想在parse_item函數中獲取parse_item函數中的parse函數的響應參數而無需設置為item對象的屬性,是否可能

不,這不可能。

響應不會轉發到管道。 您要么將響應存儲在項目中,要么使用一些外部存儲來存儲響應並將其獲取到管道中。 第二種選擇更好,並且避免了將響應存儲在項目中可能導致的許多問題(例如內存問題)。 例如,您將對某種形式的存儲的響應保存在解析回調中,將該存儲的引用保存在item字段中,並從管道中的存儲中獲取響應。

但這實際上取決於您要執行的操作, 蜘蛛中間件process_spider_output中提供了響應,因此也許您可以使用它來代替在管道中處理項目。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM