【发布时间】:2017-09-17 17:42:48
【问题描述】:
我有这个 html:
需要选择第一个和最后一个包含带有数字的a元素的li(不是带有文本prev或next) 此 xpath 查询返回我需要的第一个 li(包含页码 1 的 li):
//ul[ @class='page-numbers' ]
/li[
not(
a[ contains( @class, 'prev' ) ]
) and
not(
a[ contains( @class, 'next' ) ]
) and
position() = 1
]"
在尝试获取最后一个 li(包含页码 20 的那个)时遇到问题。试过了:
//ul[ @class='page-numbers' ]
/li[
not(
a[ contains( @class, 'prev' ) ]
) and
not(
a[ contains( @class, 'next' ) ]
) and
position() = last()
]"
和
//ul[ @class='page-numbers' ]
/li[
not(
a[ contains( @class, 'prev' ) ]
) and
not(
a[ contains( @class, 'next' ) ]
) and
last()
]"
但它不起作用。第一个返回一个空节点列表,第二个返回一个节点列表,其中包含所有带有数字 (1-20) 的 li。 有人可以帮忙吗?
【问题讨论】:
标签: xpath