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>
<a href="/navigate/names/b">B</a>
<a href="/navigate/names/c">C</a>
</p>
<p>addresses:
<a href="/navigate/addresses/a">A</a>
<a href="/navigate/addresses/b">B</a>
<a href="/navigate/addresses/c">C</a>
&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
精彩评论