文章詳情頁
python - scrapy 如何組合2個(gè)不同頁面的數(shù)據(jù),一并存儲(chǔ)
瀏覽:95日期:2022-06-29 10:02:12
問題描述
1 比如有博客列表頁 a ,獲取文章列表2 博客內(nèi)容詳情頁 b , 獲取文章正文3 如何依次獲取到文章 + 內(nèi)容 到數(shù)據(jù)庫 ?4 當(dāng)前問題主要是不知道如何組合2個(gè)不同頁面的數(shù)據(jù)
問題解答
回答1:可以用request.meta來存儲(chǔ)額外的信息, 比如
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
排行榜

熱門標(biāo)簽