You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: components/dom_crawler.rst
+24-8Lines changed: 24 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -18,9 +18,11 @@ You can install the component in many different ways:
18
18
Usage
19
19
-----
20
20
21
-
The :class:`Symfony\\Component\\DomCrawler\\Crawler` class provides methods to query and manipulate HTML and XML documents.
21
+
The :class:`Symfony\\Component\\DomCrawler\\Crawler` class provides methods
22
+
to query and manipulate HTML and XML documents.
22
23
23
-
Instance of the Crawler represents a set (:phpclass:`SplObjectStorage`) of :phpclass:`DOMElement` objects:
24
+
Instance of the Crawler represents a set (:phpclass:`SplObjectStorage`)
25
+
of :phpclass:`DOMElement` objects:
24
26
25
27
.. code-block:: php
26
28
@@ -41,7 +43,9 @@ Instance of the Crawler represents a set (:phpclass:`SplObjectStorage`) of :phpc
41
43
print $domElement->nodeName;
42
44
}
43
45
44
-
More specialized :class:`Symfony\\Component\\DomCrawler\\Link` and :class:`Symfony\\Component\\DomCrawler\\Form` classes are useful for interacting with html links and forms.
46
+
More specialized :class:`Symfony\\Component\\DomCrawler\\Link` and
47
+
:class:`Symfony\\Component\\DomCrawler\\Form` classes are useful for
48
+
interacting with html links and forms.
45
49
46
50
Node Filtering
47
51
~~~~~~~~~~~~~~
@@ -52,7 +56,10 @@ Using XPath expressions is really simplified:
.. tip:: :phpmethod:`DOMXPath::query` is used internally to actually perform an XPath query.
59
+
.. tip::
60
+
61
+
:phpmethod:`DOMXPath::query` is used internally to actually perform
62
+
an XPath query.
56
63
57
64
Filtering is even easier if you have CssSelector Component installed:
58
65
@@ -71,7 +78,10 @@ Anonymous function can be used to filter with more complex criteria:
71
78
72
79
To remove a node the anonymous function must return false.
73
80
74
-
.. note:: All filter methods return a new :class:`Symfony\\Component\\DomCrawler\\Crawler` instance with filtered content.
81
+
.. note::
82
+
83
+
All filter methods return a new :class:`Symfony\\Component\\DomCrawler\\Crawler`
84
+
instance with filtered content.
75
85
76
86
Node Traversing
77
87
~~~~~~~~~~~~~~~
@@ -109,7 +119,10 @@ Get all the child or parent nodes:
109
119
$crawler->filter('body')->children();
110
120
$crawler->filter('body > p')->parents();
111
121
112
-
.. note:: All the traversal methods return a new :class:`Symfony\\Component\\DomCrawler\\Crawler` instance.
122
+
.. note::
123
+
124
+
All the traversal methods return a new :class:`Symfony\\Component\\DomCrawler\\Crawler`
125
+
instance.
113
126
114
127
Accessing Node Values
115
128
~~~~~~~~~~~~~~~~~~~~~
@@ -142,7 +155,8 @@ Call an anonymous function on each node of the list:
142
155
return $node->nodeValue;
143
156
});
144
157
145
-
The anonymous function receives the position and the node as arguments. Result is an array of values returned by anonymous function calls.
158
+
The anonymous function receives the position and the node as arguments.
159
+
Result is an array of values returned by anonymous function calls.
146
160
147
161
Adding the Content
148
162
~~~~~~~~~~~~~~~~~~
@@ -162,7 +176,9 @@ Crawler supports multiple ways of adding the content:
162
176
$crawler->add('<html><body /></html>');
163
177
$crawler->add('<root><node /></root>');
164
178
165
-
As Crawler's implementation is based on the DOM extension it is also able to interact with native :phpclass:`DOMDocument`, :phpclass:`DOMNodeList` and :phpclass:`DOMNode` objects:
179
+
As Crawler's implementation is based on the DOM extension it is also able
180
+
to interact with native :phpclass:`DOMDocument`, :phpclass:`DOMNodeList`
0 commit comments