Skip to content

[DomCrawler] Added Crawler::matches(), ::closest(), ::outerHtml() #12225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 28, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions components/dom_crawler.rst
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@ Namespaces can be explicitly registered with the
$crawler->registerNamespace('m', 'http://search.yahoo.com/mrss/');
$crawler = $crawler->filterXPath('//m:group//yt:aspectRatio');

Verify if the current node matches a selector::

$crawler->matches('p.lorem');

.. versionadded:: 4.4

The ``matches()`` method was introduced in Symfony 4.4.

Node Traversing
~~~~~~~~~~~~~~~

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

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

Get the first parents (heading toward the document root) of the element that matches the provided selector::

$crawler->closest('p.lorem');

.. versionadded:: 4.4

The ``closest()`` method was introduced in Symfony 4.4.

.. note::

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

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

Or you can get the outer HTML of the first node using
:method:`Symfony\\Component\\DomCrawler\\Crawler::outerHtml`::

$html = $crawler->outerHtml();

.. versionadded:: 4.4

The ``outerHtml()`` method was introduced in Symfony 4.4.

Expression Evaluation
~~~~~~~~~~~~~~~~~~~~~

Expand Down