简体   繁体   English

Xpath选择数据后 <br/> 标签

[英]Xpath selecting data after the <br/> tag

I have this html: 我有这个HTML:

<div class="sys_key-facts">
  <p>
   <strong>Full-time </strong>1 year<br>
   <strong>Part-time</strong> 2 years
  </p>
</div>

I want to get the value of Part-time(After Part-time), which is: 我想获取兼职(兼职后)的值,它是:

2 years</p>

My Xpath code is : 我的Xpath代码是:

//div[@class="sys_key-facts"]/p[strong[contains(text(), "Part-time")]][preceding-sibling::br]/text() 

but this is returning empty. 但这返回的是空的。 Please let me know where I am mistaking. 请让我知道我在哪里。 Thanks 谢谢

The problem is that p[preceding-sibling::br] means that paragraph has line break sibling while br is actually a child of p - not a sibling 问题是p[preceding-sibling::br]表示该段具有换行符,而br实际上是p的子级-不是同级

So you can update your XPath as 因此,您可以将XPath更新为

//div[@class="sys_key-facts"]/p[strong[contains(text(), "Part-time")] and br]/text()[last()]

or try below XPath to get required output: 或尝试在XPath下面获取所需的输出:

//div[@class="sys_key-facts"]//strong[.="Part-time"]/following-sibling::text()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM