Skip to content

Commit 1f0fa01

Browse files
committed
feature #12225 [DomCrawler] Added Crawler::matches(), ::closest(), ::outerHtml() (lyrixx)
This PR was merged into the 4.4 branch. Discussion ---------- [DomCrawler] Added Crawler::matches(), ::closest(), ::outerHtml() fixes #12223 Commits ------- a8599cf [DomCrawler] Added Crawler::matches(), ::closest(), ::outerHtml()
2 parents 743d3db + a8599cf commit 1f0fa01

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
@@ -165,6 +165,14 @@ Namespaces can be explicitly registered with the
165165
$crawler->registerNamespace('m', 'http://search.yahoo.com/mrss/');
166166
$crawler = $crawler->filterXPath('//m:group//yt:aspectRatio');
167167

168+
Verify if the current node matches a selector::
169+
170+
$crawler->matches('p.lorem');
171+
172+
.. versionadded:: 4.4
173+
174+
The ``matches()`` method was introduced in Symfony 4.4.
175+
168176
Node Traversing
169177
~~~~~~~~~~~~~~~
170178

@@ -195,6 +203,14 @@ Get all the direct child nodes matching a CSS selector::
195203

196204
$crawler->filter('body')->children('p.lorem');
197205

206+
Get the first parents (heading toward the document root) of the element that matches the provided selector::
207+
208+
$crawler->closest('p.lorem');
209+
210+
.. versionadded:: 4.4
211+
212+
The ``closest()`` method was introduced in Symfony 4.4.
213+
198214
.. note::
199215

200216
All the traversal methods return a new :class:`Symfony\\Component\\DomCrawler\\Crawler`
@@ -337,6 +353,15 @@ and :phpclass:`DOMNode` objects::
337353

338354
The default argument of ``html()`` was introduced in Symfony 4.3.
339355

356+
Or you can get the outer HTML of the first node using
357+
:method:`Symfony\\Component\\DomCrawler\\Crawler::outerHtml`::
358+
359+
$html = $crawler->outerHtml();
360+
361+
.. versionadded:: 4.4
362+
363+
The ``outerHtml()`` method was introduced in Symfony 4.4.
364+
340365
Expression Evaluation
341366
~~~~~~~~~~~~~~~~~~~~~
342367

0 commit comments

Comments
 (0)