首頁  >  問答  >  主體

python - scrapy 如何組合2個不同頁面的資料,一併存儲

1 例如有博客列表頁a ,獲取文章列表
2 博客內容詳情頁b , 獲取文章正文
3 如何依次獲取到文章內容到數據庫?
4 當前問題主要是不知道如何組合2個不同頁面的資料

女神的闺蜜爱上我女神的闺蜜爱上我2685 天前811

全部回覆(1)我來回復

  • 巴扎黑

    巴扎黑2017-06-12 09:27:36

    可以用request.meta來儲存額外的資訊, 例如

    
    def parse_x1(self, response):
        extra = {}
        ...
        req = scrapy.Request(url2)
        req.callback = self.parse_x2
        ...
        req.meta['extra'] = extra 
        yield req
     
    def parse_x2(self, response):
        item = {}
        extra = response.meta['extra']
        item.update(extra)
        ...
        
        yield item
    

    回覆
    0
  • 取消回覆