如何添加
not(contains(.,'facebook')
, not(contains(.,'twitter')
到我的 xpath。
sites = selector.xpath("//h3[@class='r']/a[@href[not(contains(.,'google') )]]/@href")
我想找到一个没有 google
,facebook
, and twitter
的 url
请帮助我,谢谢
最佳答案
您可以使用和
加入条件:
//h3[@class='r']/a[not(contains(@href,'google')) and not(contains(@href,'facebook')) and not(contains(@href,'twitter'))]/@href")
或者,使用 .re()
method在 Selector
实例上可用:
selector.xpath("//h3[@class='r']/a/@href").re('^(?!.*(google|facebook|twitter)).*$')
此外,您可以使用 re:test()
function :
selector.xpath("//h3[@class='r']/a[not(re:test(@href, '(google|facebook|twitter)'))]/@href")
关于python - xpath 不包含 A 和 B,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28163626/