xpath 不包含 A 和 B [英] xpath not contains A and B
本文介绍了xpath 不包含 A 和 B的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何添加not(contains(.,'facebook')
, not(contains(.,'twitter')
到我的 xpath.
How can I add
not(contains(.,'facebook')
, not(contains(.,'twitter')
to my xpath.
sites = selector.xpath("//h3[@class='r']/a[@href[not(contains(.,'google') )]]/@href")
我想找到一个没有 google
、facebook
和 twitter
的网址请帮帮我,谢谢
I want to find a url without google
,facebook
,andtwitter
in it
Please help me ,thank you
推荐答案
你可以用和
加入条件:
//h3[@class='r']/a[not(contains(@href,'google')) and not(contains(@href,'facebook')) and not(contains(@href,'twitter'))]/@href")
或者,使用 Selector
实例上可用的 .re() 方法:
Or, use .re()
method available on the Selector
instance:
selector.xpath("//h3[@class='r']/a/@href").re('^(?!.*(google|facebook|twitter)).*$')
此外,您可以使用 re:test()
函数:
Also, you can use re:test()
function:
selector.xpath("//h3[@class='r']/a[not(re:test(@href, '(google|facebook|twitter)'))]/@href")
这篇关于xpath 不包含 A 和 B的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文