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

Breadcrumb

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

function Crawler::evaluate

Evaluates an XPath expression.

Since an XPath expression might evaluate to either a simple type or a \DOMNodeList, this method will return either an array of simple types or a new Crawler instance.

File

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

Class

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

Namespace

Symfony\Component\DomCrawler

Code

public function evaluate(string $xpath) : array|self {
    if (null === $this->document) {
        throw new \LogicException('Cannot evaluate the expression on an uninitialized crawler.');
    }
    $data = [];
    $domxpath = $this->createDOMXPath($this->document, $this->findNamespacePrefixes($xpath));
    foreach ($this->nodes as $node) {
        $data[] = $domxpath->evaluate($xpath, $node);
    }
    if (isset($data[0]) && $data[0] instanceof \DOMNodeList) {
        return $this->createSubCrawler($data);
    }
    return $data;
}
RSS feed
Powered by Drupal