Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Crawler.php

function Crawler::extract

Extracts information from the list of nodes.

You can extract attributes or/and the node value (_text).

Example:

$crawler->filter('h1 a')->extract(['_text', 'href']);

File

vendor/symfony/dom-crawler/Crawler.php, line 671

Class

Crawler
Crawler eases navigation of a list of \DOMNode objects.

Namespace

Symfony\Component\DomCrawler

Code

public function extract(array $attributes) : array {
    $count = \count($attributes);
    $data = [];
    foreach ($this->nodes as $node) {
        $elements = [];
        foreach ($attributes as $attribute) {
            if ('_text' === $attribute) {
                $elements[] = $node->nodeValue;
            }
            elseif ('_name' === $attribute) {
                $elements[] = $node->nodeName;
            }
            else {
                $elements[] = $node->getAttribute($attribute);
            }
        }
        $data[] = 1 === $count ? $elements[0] : $elements;
    }
    return $data;
}
RSS feed
Powered by Drupal