2015-01-27 8 views
3

not(contains(.,'facebook'), not(contains(.,'twitter')을 내 xpath에 어떻게 추가 할 수 있습니까? 이 제발 도와주세요xpath에 A와 B가 포함되어 있지 않습니다.

sites = selector.xpath("//h3[@class='r']/a[@href[not(contains(.,'google') )]]/@href") 

내가 google없이 facebook을 URL을 찾으려면, 그리고 거기에 twitter, 당신은

+0

. 나는 당신이 구글, 트위터, 또는 페이스 북이없는 URL을 원한다고 생각합니다 : 즉, 3 가지 중 하나가 URL을 실격 시키지만, 당신이 작성한 방식과 달리 3 가지가 모두 존재하면 실격 처리됩니다. –

답변

2

당신은 and과 조건을 가입 할 수 있습니다 감사합니다 :

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

또는 사용인스턴스에서 사용할 수있는 .re() method :

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") 
+0

고맙습니다! 정말 멋진 기술입니다. – user2492364

관련 문제