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