Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python xpath不包含A和B_Python_Xpath_Scrapy - Fatal编程技术网

Python xpath不包含A和B

Python xpath不包含A和B,python,xpath,scrapy,Python,Xpath,Scrapy,我怎样才能补充呢 not(包含(,'facebook'),not(包含(,'twitter')到我的xpath sites = selector.xpath("//h3[@class='r']/a[@href[not(contains(.,'google') )]]/@href") 我想找到一个没有google、facebook和twitter的url 请帮助我,谢谢你你可以加入和的条件: //h3[@class='r']/a[not(contains(@href,'google')) a

我怎样才能补充呢
not(包含(,'facebook')
not(包含(,'twitter')
到我的xpath

sites = selector.xpath("//h3[@class='r']/a[@href[not(contains(.,'google')   )]]/@href")
我想找到一个没有
google
facebook
twitter
的url
请帮助我,谢谢你

你可以加入
的条件:

//h3[@class='r']/a[not(contains(@href,'google')) and not(contains(@href,'facebook')) and not(contains(@href,'twitter'))]/@href")
或者,使用
选择器上提供的
实例:

selector.xpath("//h3[@class='r']/a/@href").re('^(?!.*(google|facebook|twitter)).*$')
此外,您还可以使用:


你需要更加谨慎地明确表达你的要求。我怀疑你想要一个没有谷歌、推特或facebook的url:也就是说,三者中的任何一个都会取消该url的资格,而按照你的书写方式,只有三者都存在时,该url才被取消资格。
selector.xpath("//h3[@class='r']/a[not(re:test(@href, '(google|facebook|twitter)'))]/@href")