Skip to content

Commit f692b02

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

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+
Selects 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+
Selects nodes matching the given `XPath expression`_.
2728
``eq(1)``
28-
Node for the specified index.
29+
Selects the node at the given index (``0`` is the first node)
2930
``first()``
30-
First node.
31+
Selects the first node (equivalent to ``eq(0)``).
3132
``last()``
32-
Last node.
33+
Selects the last node.
3334
``siblings()``
34-
Siblings.
35+
Selects all sibling nodes (nodes with the same parent).
3536
``nextAll()``
36-
All following siblings.
37+
Selects all following siblings (same parent, after the current node).
3738
``previousAll()``
38-
All preceding siblings.
39+
Selects all preceding siblings (same parent, before the current node).
3940
``ancestors()``
40-
Returns the ancestor nodes.
41+
Selects all ancestor nodes (parents, grandparents, etc., up to the ``<html>``
42+
element).
4143
``children()``
42-
Returns children nodes.
44+
Selects 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)