我正试图从https://www.lamudi.com.mx/nuevo-leon/departamento/for-rent/?page=1中提取真实状态帖子的数据
我尝试使用以下方法来刮除卧室、浴室和平方米的内容:
tags2 = soup('span',{'class':'KeyInformation-label_v2'})
for tag in tags2:
tagl = tag.get_text().strip()
print(tagl)
但我现在需要实际数据。这就是HTML的外观(卧室=recámara,浴室=baño,平方米=construidos): </span>, <span class="icon-pin"></span>, <span>Grañ Francisco Villa ote San Pedro, San Pedro Garza García</span>, <span class="PriceSection-FirstPrice">$ 7,500</span>, <span class="PriceLabel"></span>, <span class="KeyInformation-value_v2">1</span>, <span class="KeyInformation-label_v2">Recámara</span>, <span class="KeyInformation-value_v2">1</span>, <span class="KeyInformation-label_v2">Baño</span>, <span class="KeyInformation-value_v2">50 m²</span>, <span class="KeyInformation-label_v2">Construidos </span>, <span class="KeyInformation-value_v2">
类
'KeyInformation-label_v2'
只返回属性的名称。您需要类'KeyInformation-value_v2'
来获取值您还可以为每个列表添加标题。请注意,有一些重复项
输出:
对于标记内的文本,需要使用tag.string方法
来自美丽的汤documentation:
相关问题 更多 >
编程相关推荐