开发者

How to use "not" in XPath?

I want to write something of the sort:

//a[not contains(@id, 'xx')]

(meaning all the links that there 'id' att开发者_StackOverflow社区ribute doesn't contain the string 'xx')

I can't find the right syntax.


not() is a function in XPath (as opposed to an operator), so

//a[not(contains(@id, 'xx'))]


you can use not(expression) function

or

expression != true()


None of these answers worked for me for python. I solved by this

a[not(@id='XX')]

Also you can use or condition in your xpath by | operator. Such as

a[not(@id='XX')]|a[not(@class='YY')]

Sometimes we want element which has no class. So you can do like

a[not(@class)]


Use boolean function like below:

//a[(contains(@id, 'xx'))=false]
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜