Skip to content

[DomCrawler] Document innerText() method #15845

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
Sep 24, 2021
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
[DomCrawler] Document innerText() method
  • Loading branch information
javiereguiluz committed Sep 24, 2021
commit cc062a992bb40eba8c07d7d173f539c393610642
10 changes: 10 additions & 0 deletions components/dom_crawler.rst
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,16 @@ Access the value of the first node of the current selection::
// pass FALSE as the second argument to return the original text unchanged
$crawler->filterXPath('//body/p')->text('Default text content', false);

// innerText() is similar to text() but returns only the text that is
// the direct descendent of the current node, excluding any child nodes
$text = $crawler->filterXPath('//body/p')->innerText();
// if content is <p>Foo <span>Bar</span></p>
// innerText() returns 'Foo' and text() returns 'Foo Bar'

.. versionadded:: 5.4

The ``innerText()`` method was introduced in Symfony 5.4.

Access the attribute value of the first node of the current selection::

$class = $crawler->filterXPath('//body/p')->attr('class');
Expand Down