文章详情页
python - scrapy 再次请求的问题
浏览:119日期: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 - 数组原声方法中的一段代码2. python小白的基础问题 关于while循环的嵌套3. MySQL客户端吃掉了SQL注解?4. javascript - JS设置Video视频对象的currentTime时出现了问题,IE,Edge,火狐,都可以设置,反而chrom却...5. 求大神帮我看看是哪里写错了 感谢细心解答6. javascript - 百度echarts series数据更新问题7. python - Django分页和查询参数的问题8. javascript - 图片能在网站显示,但控制台仍旧报错403 (Forbidden)9. php自学从哪里开始?10. phpstady在win10上运行
排行榜
