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

Method xpath_contains_function

pyquery/cssselectpatch.py:425–442  ·  view source on GitHub ↗

Matches all elements that contain the given text >>> from pyquery import PyQuery >>> d = PyQuery(' title ') >>> d('h1:contains("title")') [ ] ..

(self, xpath, function)

Source from the content-addressed store, hash-verified

423 return xpath
424
425 def xpath_contains_function(self, xpath, function):
426 """Matches all elements that contain the given text
427
428 >>> from pyquery import PyQuery
429 >>> d = PyQuery('<div><h1/><h1 class="title">title</h1></div>')
430 >>> d('h1:contains("title")')
431 [<h1.title>]
432
433 ..
434 """
435 if function.argument_types() not in (['STRING'], ['IDENT']):
436 raise ExpressionError(
437 "Expected a single string or ident for :contains(), got %r" % (
438 function.arguments,))
439
440 value = self.xpath_literal(function.arguments[0].value)
441 xpath.add_post_condition('contains(., %s)' % value)
442 return xpath
443
444 def xpath_has_function(self, xpath, function):
445 """Matches elements which contain at least one element that matches

Callers

nothing calls this directly

Calls 1

add_post_conditionMethod · 0.80

Tested by

no test coverage detected