function Crawler::attr
Returns the attribute value of the first node of the list.
Parameters
string|null $default When not null: the value to return when the node or attribute is empty:
Throws
\InvalidArgumentException When current node is empty
File
-
vendor/
symfony/ dom-crawler/ Crawler.php, line 508
Class
- Crawler
- Crawler eases navigation of a list of \DOMNode objects.
Namespace
Symfony\Component\DomCrawlerCode
public function attr(string $attribute, ?string $default = null) : ?string {
if (!$this->nodes) {
if (null !== $default) {
return $default;
}
throw new \InvalidArgumentException('The current node list is empty.');
}
$node = $this->getNode(0);
return $node->hasAttribute($attribute) ? $node->getAttribute($attribute) : $default;
}