Skip to content

Commit 072a8f1

Browse files
committed
Merge branch '4.4'
* 4.4: [DomCrawler] Added Crawler::matches(), ::closest(), ::outerHtml()
2 parents 69db512 + 1f0fa01 commit 072a8f1

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

components/dom_crawler.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,14 @@ Namespaces can be explicitly registered with the
161161
$crawler->registerNamespace('m', 'http://search.yahoo.com/mrss/');
162162
$crawler = $crawler->filterXPath('//m:group//yt:aspectRatio');
163163

164+
Verify if the current node matches a selector::
165+
166+
$crawler->matches('p.lorem');
167+
168+
.. versionadded:: 4.4
169+
170+
The ``matches()`` method was introduced in Symfony 4.4.
171+
164172
Node Traversing
165173
~~~~~~~~~~~~~~~
166174

@@ -191,6 +199,14 @@ Get all the direct child nodes matching a CSS selector::
191199

192200
$crawler->filter('body')->children('p.lorem');
193201

202+
Get the first parents (heading toward the document root) of the element that matches the provided selector::
203+
204+
$crawler->closest('p.lorem');
205+
206+
.. versionadded:: 4.4
207+
208+
The ``closest()`` method was introduced in Symfony 4.4.
209+
194210
.. note::
195211

196212
All the traversal methods return a new :class:`Symfony\\Component\\DomCrawler\\Crawler`
@@ -321,6 +337,15 @@ and :phpclass:`DOMNode` objects::
321337
// avoid the exception passing an argument that html() returns when node does not exist
322338
$html = $crawler->html('Default <strong>HTML</strong> content');
323339

340+
Or you can get the outer HTML of the first node using
341+
:method:`Symfony\\Component\\DomCrawler\\Crawler::outerHtml`::
342+
343+
$html = $crawler->outerHtml();
344+
345+
.. versionadded:: 4.4
346+
347+
The ``outerHtml()`` method was introduced in Symfony 4.4.
348+
324349
Expression Evaluation
325350
~~~~~~~~~~~~~~~~~~~~~
326351

0 commit comments

Comments
 (0)