Skip to content Skip to sidebar Skip to footer

Xpath Not Contains A And B

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') I want to

Solution 1:

You can join conditions with and:

//h3[@class='r']/a[not(contains(@href,'google')) and not(contains(@href,'facebook')) and not(contains(@href,'twitter'))]/@href")

Or, use .re() method available on the Selector instance:

selector.xpath("//h3[@class='r']/a/@href").re('^(?!.*(google|facebook|twitter)).*$')

Also, you can use re:test() function:

selector.xpath("//h3[@class='r']/a[not(re:test(@href, '(google|facebook|twitter)'))]/@href")

Post a Comment for "Xpath Not Contains A And B"