MCPcopy Create free account
hub / github.com/gawel/pyquery / xpath_has_function

Method xpath_has_function

pyquery/cssselectpatch.py:444–469  ·  view source on GitHub ↗

Matches elements which contain at least one element that matches the specified selector. https://api.jquery.com/has-selector/ >>> from pyquery import PyQuery >>> d = PyQuery(' ') >>> d('.foo:has(".baz")')

(self, xpath, function)

Source from the content-addressed store, hash-verified

442 return xpath
443
444 def xpath_has_function(self, xpath, function):
445 """Matches elements which contain at least one element that matches
446 the specified selector. https://api.jquery.com/has-selector/
447
448 >>> from pyquery import PyQuery
449 >>> d = PyQuery('<div class="foo"><div class="bar"></div></div>')
450 >>> d('.foo:has(".baz")')
451 []
452 >>> d('.foo:has(".foo")')
453 []
454 >>> d('.foo:has(".bar")')
455 [<div.foo>]
456 >>> d('.foo:has(div)')
457 [<div.foo>]
458
459 ..
460 """
461 if function.argument_types() not in (['STRING'], ['IDENT']):
462 raise ExpressionError(
463 "Expected a single string or ident for :has(), got %r" % (
464 function.arguments,))
465 value = self.css_to_xpath(
466 function.arguments[0].value, prefix='descendant::',
467 )
468 xpath.add_post_condition(value)
469 return xpath

Callers

nothing calls this directly

Calls 1

add_post_conditionMethod · 0.80

Tested by

no test coverage detected