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

Method find

pyquery/pyquery.py:653–671  ·  view source on GitHub ↗

Find elements using selector traversing down from self: >>> m = ' Whoah! there ' >>> d = PyQuery(m) >>> d('p').find('em') [ , ] >>> d('p').eq(1).find('em') [ ]

(self, selector)

Source from the content-addressed store, hash-verified

651 return bool(self._filter_only(selector, self))
652
653 def find(self, selector):
654 """Find elements using selector traversing down from self:
655
656 >>> m = '<p><span><em>Whoah!</em></span></p><p><em> there</em></p>'
657 >>> d = PyQuery(m)
658 >>> d('p').find('em')
659 [<em>, <em>]
660 >>> d('p').eq(1).find('em')
661 [<em>]
662 """
663 xpath = self._css_to_xpath(selector)
664 results = [child.xpath(xpath, namespaces=self.namespaces)
665 for tag in self
666 for child in tag.getchildren()]
667 # Flatten the results
668 elements = []
669 for r in results:
670 elements.extend(r)
671 return self._copy(elements, parent=self)
672
673 def eq(self, index):
674 """Return PyQuery of only the element with the provided index::

Callers 3

test_findMethod · 0.80
test_endMethod · 0.80
test_html_replacementMethod · 0.80

Calls 3

_css_to_xpathMethod · 0.95
_copyMethod · 0.95
extendMethod · 0.80

Tested by 3

test_findMethod · 0.64
test_endMethod · 0.64
test_html_replacementMethod · 0.64