文章詳情頁
python - scrapy 再次請求的問題
瀏覽:131日期: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...
相關文章:
1. javascript - 有適合開發手機端Html5網頁小游戲的前端框架嗎?2. html - eclipse 標簽錯誤3. python - Pycharm的Debug用不了4. Python中使用超長的List導致內存占用過大5. python - pandas按照列A和列B分組,將列C求平均數,怎樣才能生成一個列A,B,C的dataframe6. 安全性測試 - nodejs中如何防mySQL注入7. javascript - JS變量被清空8. java - 在用戶不登錄的情況下,用戶如何添加保存到購物車?9. javascript - axios請求回來的數據組件無法進行綁定渲染10. javascript - 關于apply()與call()的問題
排行榜
