[scrapy] 2025-04-27 圈点893
摘要:在scrapy爬到东东的时候,经常会需要提到某个html标签下面的所有内容,而不包括HTML的标签,这个时候可以用如下的方法
在scrapy爬到东东的时候,经常会需要提到某个html标签下面的所有内容,而不包括HTML的标签,这个时候可以用如下的方法:
示例:
<div class='a'>
a
<p>b <strong>c<strong></p>
</div>
如果selector.xpath("//div[@class='a']/text()").extract 只能取到a
如果想要取到abc,怎么办呢?
用如下代码即可:
dall = selector.xpath("//div[@class='a']")
abc = dall.xpath('string(.)').extract()[0]