From f692b0267ad512a824eb541d05a4bba40cf985ba Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Mon, 2 Jun 2025 09:46:08 +0200 Subject: [PATCH 1/3] [DomCrawler] Add more details about some methods --- testing/dom_crawler.rst | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/testing/dom_crawler.rst b/testing/dom_crawler.rst index 9d527304f96..f6c09ded82e 100644 --- a/testing/dom_crawler.rst +++ b/testing/dom_crawler.rst @@ -21,27 +21,29 @@ selects the last one on the page, and then selects its immediate ancestor elemen Many other methods are also available: ``filter('h1.title')`` - Nodes that match the CSS selector. + Selects nodes that match the given CSS selector (which must be supported by + Symfony's :doc:`CSS Selector component `). ``filterXpath('h1')`` - Nodes that match the XPath expression. + Selects nodes matching the given `XPath expression`_. ``eq(1)`` - Node for the specified index. + Selects the node at the given index (``0`` is the first node) ``first()`` - First node. + Selects the first node (equivalent to ``eq(0)``). ``last()`` - Last node. + Selects the last node. ``siblings()`` - Siblings. + Selects all sibling nodes (nodes with the same parent). ``nextAll()`` - All following siblings. + Selects all following siblings (same parent, after the current node). ``previousAll()`` - All preceding siblings. + Selects all preceding siblings (same parent, before the current node). ``ancestors()`` - Returns the ancestor nodes. + Selects all ancestor nodes (parents, grandparents, etc., up to the ```` + element). ``children()`` - Returns children nodes. + Selects all direct child nodes of the current node. ``reduce($lambda)`` - Nodes for which the callable does not return false. + Filters the nodes using a callback; keeps only those for which it returns ``true``. Since each of these methods returns a new ``Crawler`` instance, you can narrow down your node selection by chaining the method calls:: @@ -91,3 +93,5 @@ The Crawler can extract information from the nodes:: $data = $crawler->each(function ($node, int $i): string { return $node->attr('href'); }); + +.. _`XPath expression`: https://developer.mozilla.org/en-US/docs/Web/XML/XPath From 58ef2f988667a3e2e3cf7d60ca4241c9cee2400d Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 3 Jun 2025 12:09:32 +0200 Subject: [PATCH 2/3] Add a missing trailing dot --- testing/dom_crawler.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/dom_crawler.rst b/testing/dom_crawler.rst index f6c09ded82e..20caf8ff87e 100644 --- a/testing/dom_crawler.rst +++ b/testing/dom_crawler.rst @@ -26,7 +26,7 @@ Many other methods are also available: ``filterXpath('h1')`` Selects nodes matching the given `XPath expression`_. ``eq(1)`` - Selects the node at the given index (``0`` is the first node) + Selects the node at the given index (``0`` is the first node). ``first()`` Selects the first node (equivalent to ``eq(0)``). ``last()`` From 449fd99c36cbd3dcf77e97856c0180c5ab27e843 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 3 Jun 2025 15:13:27 +0200 Subject: [PATCH 3/3] - --- testing/dom_crawler.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/dom_crawler.rst b/testing/dom_crawler.rst index 20caf8ff87e..0a5ef9d0b69 100644 --- a/testing/dom_crawler.rst +++ b/testing/dom_crawler.rst @@ -32,7 +32,7 @@ Many other methods are also available: ``last()`` Selects the last node. ``siblings()`` - Selects all sibling nodes (nodes with the same parent). + Selects all sibling nodes (nodes with the same parent, excluding the current node). ``nextAll()`` Selects all following siblings (same parent, after the current node). ``previousAll()``