From a8599cfff6d20e515dea1c1d59494e873bc0ab87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Thu, 22 Aug 2019 11:32:56 +0200 Subject: [PATCH] [DomCrawler] Added Crawler::matches(), ::closest(), ::outerHtml() --- components/dom_crawler.rst | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) 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 ~~~~~~~~~~~~~~~~~~~~~