您的位置:首頁技術文章
文章詳情頁

python - scrapy 再次請求的問題

瀏覽:117日期:2022-08-17 18:54:48

問題描述

如:item[’url’]=response.xpath(’a/@href’)分析出一個鏈接,然后想從這個鏈接里的網頁再獲取一些元素,放入item[’other’]。應該怎么寫,謝謝。

問題解答

回答1:

def parse_page1(self, response): for url in urls:item = MyItem()item[’url’] = urlrequest = scrapy.Request(url,callback=self.parse_page2)# request = scrapy.Request('http://www.example.com/some_page.html',dont_filter=True,callback=self.parse_page2)request.meta[’item’] = itemyield requestdef parse_page2(self, response): item = response.meta[’item’] item[’other’] = response.xpath(’/other’) yield item

最后附上官方文檔https://doc.scrapy.org/en/lat...中文翻譯版http://scrapy-chs.readthedocs...

標簽: Python 編程
相關文章:
国产综合久久一区二区三区