xpath 选择两个节点之间的元素
这是我的 HTML:
<table dir = "rtl .......">
<tbody>
<script src = "get.aspx?type=js&file=ajax&rev=3"......>
<script language = "JavaScript" src = "get.aspx?type=js&file=mc&rev=6"></script>
<script>..</script>
<tr>
<td class = "d2"...>..</td>
</tr>
<tr>..</tr> <--
<tr>..</tr> <--
<tr>..</tr> <-- these elements
<tr>..</tr> <--
<tr>..</tr> <--
<tr>..</tr> <--
<tr>..</tr> <--
<tr>
<td class = "d2"...>..</td>
</tr>
<script>..</script>
<tr>..</tr>
<tr>..</tr>
<tr>..</tr>
如何计算或选择两个 How would I count or select all
xpath 会很长,所以要振作起来: 要选择实际节点而不仅仅是计数,只需删除第一个计数: To select the actual nodes and not have just the count, simply remove the first count : 这里发生了各种各样的事情: There are various things happening here notably: 元素之间的所有 元素,其 id 为 d2
?
<tr>
elements between the two <td>
elements whose id is d2
?count(//tr[preceding-sibling::tr/td[@class = 'd2']][count(.|//tr[following-sibling::tr/td[@class = 'd2']])=count(//tr[following-sibling::tr/td[@class = 'd2']])])
//tr[preceding-sibling::tr/td[@class = 'd2']][count(.|//tr[following-sibling::tr/td[@class = 'd2']])=count(//tr[following-sibling::tr/td[@class = 'd2']])]