使用XPath选择下一个链接

Pab*_*blo 3 xml xpath parsing html-parsing

我必须编写一个XPath表达式来获取html bellow中的href属性,它紧跟在标记为"current-page"的那个之后(在示例#noimportant/2中).

<dd>
    <a href="#notimportant/1" class="current-page">1</a>
    <a href="#notimportant/2">2</a>
    <a href="#notimportant/3">3</a>
    <a href="#notimportant/4">4</a>
    <!-- EDIT: Do not return the next sibling if @href ends with /last -->
    <a href="#notimportant/last">last</a>
</dd>
Run Code Online (Sandbox Code Playgroud)

我想从//a[@class='current-page']/../next-sibling-of-first-node/@href这样的东西开始,但我被困在这里......

有人可以帮我这个吗?我已经google了,但XPath不是我最喜欢的技能(不,我不能使用jQuery.它不是一个webapp).

Mat*_*hen 8

//a[@class='current-page']/following-sibling::a[1]
Run Code Online (Sandbox Code Playgroud)

  • +1,惊人的答案,@马修!9秒=) (5认同)