Matches all elements that contain the given text >>> from pyquery import PyQuery >>> d = PyQuery(' title ') >>> d('h1:contains("title")') [ ] ..
(self, xpath, function)
| 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 |
nothing calls this directly
no test coverage detected