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

Method xpath_eq_function

pyquery/cssselectpatch.py:368–386  ·  view source on GitHub ↗

Matches a single element by its index:: >>> from pyquery import PyQuery >>> d = PyQuery(' ') >>> d('h1:eq(0)') [ ] >>> d('h1:eq(1)') [ ] ..

(self, xpath, function)

Source from the content-addressed store, hash-verified

366 return xpath
367
368 def xpath_eq_function(self, xpath, function):
369 """Matches a single element by its index::
370
371 >>> from pyquery import PyQuery
372 >>> d = PyQuery('<div><h1 class="first"/><h1 class="last"/></div>')
373 >>> d('h1:eq(0)')
374 [<h1.first>]
375 >>> d('h1:eq(1)')
376 [<h1.last>]
377
378 ..
379 """
380 if function.argument_types() != ['NUMBER']:
381 raise ExpressionError(
382 "Expected a single integer for :eq(), got %r" % (
383 function.arguments,))
384 value = int(function.arguments[0].value)
385 xpath.add_post_condition('position() = %s' % (value + 1))
386 return xpath
387
388 def xpath_gt_function(self, xpath, function):
389 """Matches all elements with an index over the given one::

Callers

nothing calls this directly

Calls 1

add_post_conditionMethod · 0.80

Tested by

no test coverage detected