我已经试着弄清楚这一点有一段时间了,但我无法理解。我试过使用following-sibling
,但它对我不起作用。这些类确实是通用的。我试图使用<strong>
标记中的文本来识别并提取同级内容:
<div class="generic-class">
<p class="generic-class2">
<strong>Content title</strong>
"
Dont Need "
<br>
</p>
</div>
<div class="generic-class">
<p class="generic-class2">
<strong>Content title2</strong>
"
Needed Content "
<br>
</p>
</div>
<div class="generic-class">
<p class="generic-class2">
<strong>Content title3</strong>
"
Dont Need "
<br>
</p>
</div>
<div class="generic-class">
<p class="generic-class2">
<strong>Content title4</strong>
"
Dont Need "
<br>
</p>
</div>
我尝试使用下面的,但没有成功,然后我意识到文本实际上在<p>
标签中,所以它不是兄弟。:
normalize-space(//*[@class="generic-class"]/p/strong/following-sibling::text())
有没有一种方法可以让我在<strong>
标签"内容标题2"中找到文本,然后在父级中获取文本?
任何帮助都将是惊人的,谢谢!
这个应该返回"Needed Content"
:
normalize-space(//p/strong[.="Content title2"]/following-sibling::text())