Skip to content

[DomCrawler] Give choice of used parser #18009

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
Mar 6, 2023
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
20 changes: 20 additions & 0 deletions components/dom_crawler.rst
Original file line number Diff line number Diff line change
Expand Up @@ -651,8 +651,28 @@ another given base URI::
UriResolver::resolve('?a=b', 'http://localhost/bar#foo'); // http://localhost/bar?a=b
UriResolver::resolve('../../', 'http://localhost/'); // http://localhost/

Using a HTML5 Parser
~~~~~~~~~~~~~~~~~~~~

You can specify to the :class:`Symfony\\Component\\DomCrawler\\Crawler` to use
an HTML5 parser when instantiating it by setting the ``useHtml5Parser`` constructor
argument to ``true``::

use Symfony\Component\DomCrawler\Crawler;

$crawler = new Crawler(null, $uri, useHtml5Parser: true);

By doing do, the crawler will use the parser from the `masterminds/html5`_ library internally to parse
documents.

.. versionadded:: 6.3

The ``useHtml5Parser`` argument was introduced in Symfony 6.3.

Learn more
----------

* :doc:`/testing`
* :doc:`/components/css_selector`

.. _`masterminds/html5`: https://packagist.org/packages/masterminds/html5