到目前为止,这是我的HTML代码:
<tr valign="top">
<td nowrap="x">Citation(s)</td>
<td>
<span class="pubmed_id" id="26472973">
<a href="/pubmed/26472973">26472973</a>
</span>
</td>
</tr>
我想提取数字26472973
,该数字对于数据库中的每个条目都会改变。
答案 0 :(得分:1)
不清楚是要从属性@id
还是从后面的a
元素中获取值。
因此,对于属性值,请尝试以下XPath:
//tr[@valign='top']/td/span[@class='pubmed_id']/@id
或者,对于元素的a
值,请使用以下XPath:
//tr[@valign='top']/td/span[@class='pubmed_id']/a/text()
在两种情况下,结果均为26472973
。
答案 1 :(得分:0)
如果您只想要“引用”,请尝试以下操作:
//tr/td[text()='Citation(s)']/following-sibling::td/span/@id