[英]Xpath selecting data after the <br/> tag
我有這個HTML:
<div class="sys_key-facts">
<p>
<strong>Full-time </strong>1 year<br>
<strong>Part-time</strong> 2 years
</p>
</div>
我想獲取兼職(兼職后)的值,它是:
2 years</p>
我的Xpath代碼是:
//div[@class="sys_key-facts"]/p[strong[contains(text(), "Part-time")]][preceding-sibling::br]/text()
但這返回的是空的。 請讓我知道我在哪里。 謝謝
問題是p[preceding-sibling::br]
表示該段具有換行符,而br
實際上是p
的子級-不是同級
因此,您可以將XPath更新為
//div[@class="sys_key-facts"]/p[strong[contains(text(), "Part-time")] and br]/text()[last()]
或嘗試在XPath下面獲取所需的輸出:
//div[@class="sys_key-facts"]//strong[.="Part-time"]/following-sibling::text()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.