diff --git a/components/dom_crawler.rst b/components/dom_crawler.rst index 855fd707446..44aadd6a208 100644 --- a/components/dom_crawler.rst +++ b/components/dom_crawler.rst @@ -165,6 +165,14 @@ Namespaces can be explicitly registered with the $crawler->registerNamespace('m', 'http://search.yahoo.com/mrss/'); $crawler = $crawler->filterXPath('//m:group//yt:aspectRatio'); +Verify if the current node matches a selector:: + + $crawler->matches('p.lorem'); + +.. versionadded:: 4.4 + + The ``matches()`` method was introduced in Symfony 4.4. + Node Traversing ~~~~~~~~~~~~~~~ @@ -195,6 +203,14 @@ Get all the direct child nodes matching a CSS selector:: $crawler->filter('body')->children('p.lorem'); +Get the first parents (heading toward the document root) of the element that matches the provided selector:: + + $crawler->closest('p.lorem'); + +.. versionadded:: 4.4 + + The ``closest()`` method was introduced in Symfony 4.4. + .. note:: All the traversal methods return a new :class:`Symfony\\Component\\DomCrawler\\Crawler` @@ -337,6 +353,15 @@ and :phpclass:`DOMNode` objects:: The default argument of ``html()`` was introduced in Symfony 4.3. + Or you can get the outer HTML of the first node using + :method:`Symfony\\Component\\DomCrawler\\Crawler::outerHtml`:: + + $html = $crawler->outerHtml(); + + .. versionadded:: 4.4 + + The ``outerHtml()`` method was introduced in Symfony 4.4. + Expression Evaluation ~~~~~~~~~~~~~~~~~~~~~