我有这个:
li.current+li>a
但是我只掌握了XPath的基本知识。 我需要它用于AutoPager Firefox扩展。
我也想只参加第一场比赛。
答案 0 :(得分:3)
如果您的li
属于许多课程,那么......
//li[contains(concat(' ',normalize-space(@class),' '),' current ')]/following-sibling::*[1]/self::li/a
为了清晰起见,这里有许多分解的相同内容:
//li[contains(
concat(' ',normalize-space(@class),' '),
' current '
)
]/following-sibling::*[1]/self::li/a
引用:http://pivotallabs.com/users/alex/blog/articles/427-xpath-css-class-matching
我使用以下XML使用Online XPath 2 evaluator对其进行了测试:
<html>
<head>
<title>
Consume usage app support thread #2 - Apps - iPhone - Whirlpool Forums
</title>
</head>
<body>
<div id="root">
<ul id="top_pagination" class="pagination ">
<li class="first">
<a href="/forum-replies.cfm?t=1543353">
first: 5 months ago
</a>
</li>
<li class=" ">
<a href="/forum-replies.cfm?t=1543353">
1
</a>
</li>
<li class=" ">
<a href="/forum-replies.cfm?t=1543353&p=2">
2
</a>
</li>
<li class=" ">
<a href="/forum-replies.cfm?t=1543353&p=3">
3
</a>
</li>
<li class=" ">
<a href="/forum-replies.cfm?t=1543353&p=4">
4
</a>
</li>
<li class=" ">
<a href="/forum-replies.cfm?t=1543353&p=5">
5
</a>
</li>
<li class=" ">
<a href="/forum-replies.cfm?t=1543353&p=6">
6
</a>
</li>
<li class=" ">
<a href="/forum-replies.cfm?t=1543353&p=7">
7
</a>
</li>
<li class=" ">
<a href="/forum-replies.cfm?t=1543353&p=8">
8
</a>
</li>
<li class=" ">
<a href="/forum-replies.cfm?t=1543353&p=9">
9
</a>
</li>
<li class=" ">
<a href="/forum-replies.cfm?t=1543353&p=10">
10
</a>
</li>
<li class=" ">
<a href="/forum-replies.cfm?t=1543353&p=11">
11
</a>
</li>
<li class=" ">
<a href="/forum-replies.cfm?t=1543353&p=12">
12
</a>
</li>
<li class=" ">
<a href="/forum-replies.cfm?t=1543353&p=13">
13
</a>
</li>
<li class=" ">
<a href="/forum-replies.cfm?t=1543353&p=14">
14
</a>
</li>
<li class=" ">
<a href="/forum-replies.cfm?t=1543353&p=15">
15
</a>
</li>
<li class=" ">
<a href="/forum-replies.cfm?t=1543353&p=16">
16
</a>
</li>
<li class=" ">
<a href="/forum-replies.cfm?t=1543353&p=17">
17
</a>
</li>
<li class=" ">
<a href="/forum-replies.cfm?t=1543353&p=18">
18
</a>
</li>
<li class=" ">
<a href="/forum-replies.cfm?t=1543353&p=19">
19
</a>
</li>
<li class=" ">
<a href="/forum-replies.cfm?t=1543353&p=20">
20
</a>
</li>
<li class=" ">
<a href="/forum-replies.cfm?t=1543353&p=21">
21
</a>
</li>
<li class=" ">
<a href="/forum-replies.cfm?t=1543353&p=22">
22
</a>
</li>
<li class=" ">
<a href="/forum-replies.cfm?t=1543353&p=23">
23
</a>
</li>
<li class=" ">
<a href="/forum-replies.cfm?t=1543353&p=24">
24
</a>
</li>
<li class=" ">
<a href="/forum-replies.cfm?t=1543353&p=25">
25
</a>
</li>
<li class="current ">
<a href="/forum-replies.cfm?t=1543353&p=26">
26
</a>
</li>
<li class=" ">
<a href="/forum-replies.cfm?t=1543353&p=27">
27
</a>
</li>
<li class="last">
<a href="/forum-replies.cfm?t=1543353&p=-1&#bottom">
last: 2 hours ago
</a>
</li>
</ul>
</div>
</body>
</html>
您应该注意,您链接的页面作为输入 - http://forums.whirlpool.net.au/forum-replies.cfm?t=1543353&p=26 - 是HTML,而不是XML:
<br>
等未公开标签,必须为<br />
...因此,您可能无法将其用作XPath评估的输入。
答案 1 :(得分:0)
li.current + li > a
映射到:
//li[@class='current']/following-sibling::*[1]/self::li/a
如果要选择第一个a
子元素,则CSS选择器应为:
li.current + li > a:first-child
映射到:
//li[@class='current']/following-sibling::*[1]/self::li/a[1]