python - scrapy 再次請求的問題
問題描述
如:item[’url’]=response.xpath(’a/@href’)分析出一個鏈接,然后想從這個鏈接里的網(wǎng)頁再獲取一些元素,放入item[’other’]。應(yīng)該怎么寫,謝謝。
問題解答
回答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...
相關(guān)文章:
1. mysql - 10g數(shù)據(jù)庫如何遷移2. php - 有關(guān)sql語句反向LIKE的處理3. 在視圖里面寫php原生標(biāo)簽不是要迫不得已的情況才寫嗎4. 獲取上次登錄ip的原理是啥?5. node.js - session怎么存到cookie,然后服務(wù)器重啟后還能獲取。數(shù)據(jù)庫不用mongodb或redis,數(shù)據(jù)庫是mysql6. 求救一下,用新版的phpstudy,數(shù)據(jù)庫過段時間會消失是什么情況?7. 為什么說非對象調(diào)用成員函數(shù)fetch()8. fetch_field_direct()報錯9. 為什么點擊登陸沒反應(yīng)10. mysql多表聯(lián)合查詢優(yōu)化的問題
