Here is part of my code:
$heading_text = '';
$heading_nodes = $crawler->filter($heading_selector);
if(count($heading_nodes->siblings()) > 0) {
$heading_text = str_replace('Something', 'Else', htmlentities($heading_nodes->eq(0)->text()));
}
I know that some of the pages I am crawling will not have any element with the $heading_selector
. However, that's why I was relying on siblings()
to calculate the number of headings and proceed if the value was more than 0.
However, I still got the same error Fatal error: Uncaught InvalidArgumentException: The current node list is empty.
. The error was caused by $heading_nodes->siblings()
.
So, if I cannot use count
with siblings()
to check if a DOM element exists without throwing an error, what else can I do?
I am using the Symfony DOM crawler: https://symfony.com/doc/current/components/dom_crawler.html.
Thanks.