文章詳情頁
python - scrapy 再次請求的問題
瀏覽:106日期: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. android - NavigationView 的側滑菜單中如何保存新增項(通過程序添加)2. php7.3.4中怎么開啟pdo驅動3. python-mysqldb - 這樣結構的mysql表,如何快速update4. 提示語法錯誤語法錯誤: unexpected ’abstract’ (T_ABSTRACT)5. 編程學習心得分享(共80條)6. 這段代碼既不提示錯誤也看不到結果,請老師明示錯在哪里,謝謝!7. 老師 我是一個沒有學過php語言的準畢業生 我希望您能幫我一下8. ueditor上傳服務器提示后端配置項沒有正常加載,求助!!?。?!9. 備份恢復 - php備份mysql數據庫方案有哪些?10. tp5 不同控制器中的變量調用問題
排行榜
