如何在Xpath中选择文本?

时间:2015-11-08 09:27:16

标签: select xpath text

我想从网页内容中选择一些细节

<div id="realty_widget_property_description" class="property_block realty_widget_property_description widget widget-2 alt">
<p class="title "><strong>Apartment for Rent </strong></p>
<div class="property-description ">
        <p class="property_description">
        </p><p>– Property ID: P-000324<br>
– Location: Phsar Chas<br>
– Price: $350/month<br>
– Bed/Bath: 2 beds / 2 Baths<br>
– Size: 4m x 18m<br>
– Story: 1st<br>
– Fully Furnished<br>
– Description: This apartment is in residential area and good location for living with comfortable and fresh air. There are 2 bedrooms, 2 bathrooms, a living room, a kitchen and the balcony. Close to everywhere in town such as school, market, clinic, Bank, coffee shop and just ride a few minutes to Phsar Chas Market.<br>

如果他们都在同一个班级,我如何选择物业ID,位置,价格,大小,故事和描述?

1 个答案:

答案 0 :(得分:1)

使用例如substring-after(//div[@id = 'realty_widget_property_description']/div[@class = 'property-description ']/p[2]/text()[1], ': ')提取字符串值。但请注意,XPath表达式返回的是字符串值而不是节点,因此您需要确保使用支持该值的XPath API。