开发者

How to target only the 'names' links using XPath?

I have two groups of links: names and addresses in HTML structured like this:

<div class="navbar">
  <p>names:
    <a href="/navigate/names/a">A</a>&nbsp;
    <a href="/navigate/names/b">B</a>&nbsp;
    <a href="/navigate/names/c">C</a>&nbsp;
  </p>
  <p>addresses:
    <a href="/navigate/addresses/a">A</a>&nbsp;
    <a href="/navigate/addresses/b">B</a>&nbsp;
    <a href="/navigate/addresses/c">C</a>&nbsp;
  &l开发者_StackOverflow社区t;/p>
</div>

How do I target only the names links using XPath?


/div/p/a[starts-with(@href, '/navigate/names')]

or

/div/p/a[contains(@href, 'names')]

or

/div/p[contains(text(),'names:')]/a


Use:

/*/p[starts-with(., 'names:')]/a
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜