Skip to content

Commit 89718f0

Browse files
committed
[DomCrawler] Add more details about some methods
1 parent 6679bc6 commit 89718f0

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

testing/dom_crawler.rst

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,29 @@ selects the last one on the page, and then selects its immediate ancestor elemen
2121
Many other methods are also available:
2222

2323
``filter('h1.title')``
24-
Nodes that match the CSS selector.
24+
Finds nodes that match the given CSS selector (which must be supported by
25+
Symfony's :doc:`CSS Selector component </components/css_selector>`).
2526
``filterXpath('h1')``
26-
Nodes that match the XPath expression.
27+
Finds nodes matching the given `XPath expression`_.
2728
``eq(1)``
28-
Node for the specified index.
29+
Returns the node at the given index (``0`` is the first node).
2930
``first()``
30-
First node.
31+
Returns the first node (equivalent to ``eq(0)``).
3132
``last()``
32-
Last node.
33+
Returns the last node.
3334
``siblings()``
34-
Siblings.
35+
Returns all sibling nodes (nodes with the same parent, excluding the current node).
3536
``nextAll()``
36-
All following siblings.
37+
Returns all following siblings (same parent, after the current node).
3738
``previousAll()``
38-
All preceding siblings.
39+
Returns all preceding siblings (same parent, before the current node).
3940
``ancestors()``
40-
Returns the ancestor nodes.
41+
Returns all ancestor nodes (parents, grandparents, etc., up to the ``<html>``
42+
element).
4143
``children()``
42-
Returns children nodes.
44+
Returns all direct child nodes of the current node.
4345
``reduce($lambda)``
44-
Nodes for which the callable does not return false.
46+
Filters the nodes using a callback; keeps only those for which it returns ``true``.
4547

4648
Since each of these methods returns a new ``Crawler`` instance, you can
4749
narrow down your node selection by chaining the method calls::
@@ -91,3 +93,5 @@ The Crawler can extract information from the nodes::
9193
$data = $crawler->each(function ($node, int $i): string {
9294
return $node->attr('href');
9395
});
96+
97+
.. _`XPath expression`: https://developer.mozilla.org/en-US/docs/Web/XML/XPath

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy