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

Method xpath_lt_function

pyquery/cssselectpatch.py:406–423  ·  view source on GitHub ↗

Matches all elements with an index below the given one:: >>> from pyquery import PyQuery >>> d = PyQuery(' ') >>> d('h1:lt(1)') [ ] ..

(self, xpath, function)

Source from the content-addressed store, hash-verified

404 return xpath
405
406 def xpath_lt_function(self, xpath, function):
407 """Matches all elements with an index below the given one::
408
409 >>> from pyquery import PyQuery
410 >>> d = PyQuery('<div><h1 class="first"/><h1 class="last"/></div>')
411 >>> d('h1:lt(1)')
412 [<h1.first>]
413
414 ..
415 """
416 if function.argument_types() != ['NUMBER']:
417 raise ExpressionError(
418 "Expected a single integer for :gt(), got %r" % (
419 function.arguments,))
420
421 value = int(function.arguments[0].value)
422 xpath.add_post_condition('position() < %s' % (value + 1))
423 return xpath
424
425 def xpath_contains_function(self, xpath, function):
426 """Matches all elements that contain the given text

Callers

nothing calls this directly

Calls 1

add_post_conditionMethod · 0.80

Tested by

no test coverage detected