从跨度 class XPath 中检索值
Retrieve value from span class XPath
我正在尝试从该网站抓取一些信息 https://www.gumtree.co.za (https://www.gumtree.co.za/a-house-rentals-flat-rentals-offered/tamboerskloof/studio-flatlet-in-tamboerskloof/1005754794350910092234609 这是我从中获取信息的 属性 的 link);更具体地说,我正在尝试从这些范围 classes:
中获取信息
<div class="attribute">
<span class="name">Bathrooms (#):</span>
<span class="value">1</span>
</div>
我首先要检查跨度 class 中是否有浴室,然后取值。这就是我现在拥有的:
bathrooms=response.xpath("//span[contains(text(),'Bathrooms')]/span[@class='value']text()").extract_first()
然而,我没有得到任何东西。
有什么建议吗?谢谢!
这是提取所有兄弟姐妹的正确方法。
浴室=response.xpath("//span[contains(text(),'Bathrooms')]/following-sibling::*").extract_first()
更多可以参考这个:XPath Axes
希望这有帮助。
我正在尝试从该网站抓取一些信息 https://www.gumtree.co.za (https://www.gumtree.co.za/a-house-rentals-flat-rentals-offered/tamboerskloof/studio-flatlet-in-tamboerskloof/1005754794350910092234609 这是我从中获取信息的 属性 的 link);更具体地说,我正在尝试从这些范围 classes:
中获取信息<div class="attribute">
<span class="name">Bathrooms (#):</span>
<span class="value">1</span>
</div>
我首先要检查跨度 class 中是否有浴室,然后取值。这就是我现在拥有的:
bathrooms=response.xpath("//span[contains(text(),'Bathrooms')]/span[@class='value']text()").extract_first()
然而,我没有得到任何东西。
有什么建议吗?谢谢!
这是提取所有兄弟姐妹的正确方法。 浴室=response.xpath("//span[contains(text(),'Bathrooms')]/following-sibling::*").extract_first()
更多可以参考这个:XPath Axes 希望这有帮助。