如何根据另一个同级节点的属性选择节点属性?我想要实现的是从所有节点中提取链接(href 值),然后是属性 class="body-table-news-loss" 的节点跨度,即选择器应该返回https://finance.yahoo。 com/news/inspiremd-announces-planned-recapitalization-120000752.html在下面的示例中。我试过了
"//tr[td/span[@class='body-table-news-loss']]/a/@href"
及其类似的变体,但我没有得到想要的结果,因为我不知道如何向 XPath 选择器解释层次结构级别。非常感谢您的帮助。
<tr>
<td>Nov-29-17 07:00AM
</td>
<td align="left">
<a href="https://finance.yahoo.com/news/inspiremd-announces-planned-
recapitalization-120000752.html">InspireMD Announces Planned
Recapitalization
</a>
<span class="body-table-news-loss">-51.29%</span>
</td>
</tr>
<tr>
<td >Nov-07-17 04:05PM
</td>
<td align="left">
<a href="https://finance.yahoo.com/news/inspiremd-announces-third-
quarter-2017-210500523.html">InspireMD Announces Third Quarter 2017
Results; CGuard(TM) Revenue Increases 90% Versus Same Period Last Year
</a>
<span class="body-table-news-gain">+5.94%</span>
</td>
</tr>