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

Method eq

pyquery/pyquery.py:673–692  ·  view source on GitHub ↗

Return PyQuery of only the element with the provided index:: >>> d = PyQuery(' Hi Bye ') >>> d('p').eq(0) [ ] >>> d('p').eq(1) [ ] >>> d('p').eq(2) [] ..

(self, index)

Source from the content-addressed store, hash-verified

671 return self._copy(elements, parent=self)
672
673 def eq(self, index):
674 """Return PyQuery of only the element with the provided index::
675
676 >>> d = PyQuery('<p class="hello">Hi</p><p>Bye</p><div></div>')
677 >>> d('p').eq(0)
678 [<p.hello>]
679 >>> d('p').eq(1)
680 [<p>]
681 >>> d('p').eq(2)
682 []
683
684 ..
685 """
686 # Slicing will return empty list when index=-1
687 # we should handle out of bound by ourselves
688 try:
689 items = self[index]
690 except IndexError:
691 items = []
692 return self._copy(items, parent=self)
693
694 def each(self, func):
695 """apply func on each nodes

Callers 2

test_get_rootMethod · 0.80
test_fn_with_kwargsMethod · 0.80

Calls 1

_copyMethod · 0.95

Tested by 2

test_get_rootMethod · 0.64
test_fn_with_kwargsMethod · 0.64