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. git - 使用淘寶npm安裝hexo出現(xiàn)問題?2. html5和Flash對抗是什么情況?3. 小程序怎么加外鏈,語句怎么寫!求救新手,開文檔沒發(fā)現(xiàn)4. javascript - vue-resource中如何設(shè)置全局的timeout?5. javascript - 在 vue里面用import引入js文件,結(jié)果為undefined6. PC 手機兼容的 編輯器7. php如何獲取訪問者路由器的mac地址8. 多選框?qū)戇M數(shù)據(jù)庫怎么寫9. 求教一個mysql建表分組索引問題10. thinkPHP5中獲取數(shù)據(jù)庫數(shù)據(jù)后默認選中下拉框的值,傳遞到后臺消失不見。有圖有代碼,希望有人幫忙
