scrapy 根据类名进行刮取

8ulbf1ek  于 2022-11-23  发布在  其他
关注(0)|答案(1)|浏览(153)

我想从这里提取地址“Calle Tiera Del Soconusco No. 252”。

<td class="type-address"><span>Calle Tiera Del Soconusco No. 252 </span></td>

我已经尝试了以下代码,但我无法获得必要的信息。

infor = response2.xpath("td[2]/td[contains(@class,'type-address')]").get()
infor2= response2.xpath("td[2]/@class").get()
wvmv3b1j

wvmv3b1j1#

所以父元素是一个类为“type-address”的<td>,那么父元素有一个实际包含文本的子元素<span>
所以试试看:

info = response.xpath('//td[@class="type-address"]/span/text()').get()

# or if there is more than 1

info = response.xpath('//td[@class="type-address"]/span/text()').getall()

相关问题