获得最接近标签外文字的值

时间:2018-11-28 14:06:01

标签: html xml xpath

我知道标题很糟糕,但是我什至不知道该如何表达我想要的东西。这是代码:

<div class="card card-list">
<a href="javascript:;" data-id="10" class="card-list-item ">
<img src="/Images/ranked/a.png" style="width:25px;">
Ranked Duel 1v1
<span class="badge">874</span>
</a>
<a href="javascript:;" data-id="11" class="card-list-item ">
<img src="/Images/ranked/b.png" style="width:25px;">
Ranked Doubles 2v2
<span class="badge">1188</span>
</a>
<a href="javascript:;" data-id="12" class="card-list-item ">
<img src="/Images/ranked/c.png" style="width:25px;">
Ranked Solo Standard 3v3
<span class="badge">1047</span>
</a>
<a href="javascript:;" data-id="13" class="card-list-item ">
<img src="/Images/ranked/d.png" style="width:25px;">
Ranked Standard 3v3
<span class="badge">1417</span>
</a>
</div>

xpath是否可以从确定的未标记文本中提取类值“徽章”?例如,我想从“排名标准3v3”文本中提取“徽章”值(1417)。 或者,如果我为“ Ranked Doubles 2v2”发布xpath,则它应返回“徽章”值1188。

1 个答案:

答案 0 :(得分:0)

尝试在XPath下面使用,以获取“排名标准3v3”的适当值

//a[contains(., "Ranked Standard 3v3")]/span/text()

//text()[normalize-space()="Ranked Standard 3v3"]/following-sibling::span/text()