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\DomCrawlerCode
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;
}