XPath:: 获得以下兄弟姐妹 [英] XPath:: Get following Sibling
问题描述
我有以下 HTML 结构:我正在尝试构建一个强大的方法来提取第二个颜色摘要元素,因为 DOM 中会有很多这样的标签.
I have following HTML Structure: I am trying to build a robust method to extract second color digest element since there will be many of these tag within the DOM.
<table>
<tbody>
<tr bgcolor="#AAAAAA">
<tr>
<tr>
<tr>
<tr>
<td>Color Digest </td>
<td>AgArAQICGQMVBBwTIRQHIwg0GUMURAZTBWQJcwV0AoEDAQ </td>
</tr>
<tr>
<td>Color Digest </td>
<td>2,43,2,25,21,28,0,0,0,0,0,0,0,0,0,0,0,0,0,0,33,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,25,0,0,0,0,0,0,0,0,0,0,0,0,0,0,20,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, </td>
</tr>
</tbody>
</table>
我正在尝试提取具有解码值的第二个颜色摘要"td 元素.
I am trying to extract the Second "Color Digest" td element that has the decoded value.
我写了下面的 xpath 但我没有得到第二个 td 元素,而不是得到第二个.
I wrote the following xpath but instead of getting the second i am not getting the second td element.
//td[text() = ' Color Digest ']/following-sibling::td[2]
当我将它更改为 td[2] 到 td[1] 时,我得到了两个元素.
And when I change it to td[2] to td[1] I get both the elements.
推荐答案
您应该寻找第二个 tr 的 td 等于"Color Digest ",然后您需要查看第一个 td 的以下兄弟在 tr 或第二个 td 中.
You should be looking for the second tr that has the td that equals ' Color Digest ', then you need to look at either the following sibling of the first td in the tr, or the second td.
尝试以下操作:
//tr[td='Color Digest'][2]/td/following-sibling::td[1]
或
//tr[td='Color Digest'][2]/td[2]
http://www.xpathtester.com/saved/76bb0bca-1896-43b7-8312-54f924a98a89
这篇关于XPath:: 获得以下兄弟姐妹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!