获得兄弟/姐妹节点的价值

时间:2022-07-27 20:19:31

Let's say on a page I have alot of this repeated:

让我们在一个页面上说我有很多这样的重复:

<div class="entry">
  <h4>Magic:</h4>
  <a>Edit</a> 
  <a>Delete</a>
</div>

But the nodeValue of h4 is not repeated. How do I get the nodeValue of the a based on the h4 tag's nodeValue? Get content of the sister a nodes of h4 where h4 content is Magic:.

但是不重复h4的nodeValue。如何根据h4标签的nodeValue获取a的nodeValue?获取姐妹的内容h4的节点,其中h4内容为Magic:。

1 个解决方案

#1


5  

Use this XPath:

使用此XPath:

//div/h4[. = 'Magic:']/following-sibling::a[1]

It selects 1st following-sibling a element of h4 with value Magic:.

它选择第一个跟随兄弟的h4元素,其值为Magic:。

#1


5  

Use this XPath:

使用此XPath:

//div/h4[. = 'Magic:']/following-sibling::a[1]

It selects 1st following-sibling a element of h4 with value Magic:.

它选择第一个跟随兄弟的h4元素,其值为Magic:。