Goutte
Goutte copied to clipboard
The current node list is empty.
Hi,
I'm getting this error, The current node list is empty.
Is there away of it just skipping this element if it's unable to scrape the data? e.g. $company_crawler->filter('a.cp-links-url')->attr('href')
Thanks.
Hi,
you could wrap that line within an try catch block:
try{
$company_crawler->filter('a.cp-links-url')->attr('href')
} catch(Exception $e) { // I guess its InvalidArgumentException in this case
// Node list is empty
}
Or count the node list before you try to get that attribute:
if ($company_crawler->filter('a.cp-links-url')->count() > 0 ) {
$cpLinkUrls = $company_crawler->filter('a.cp-links-url')->attr('href')
}
Another way we can do this if fails, works for me.
<?php
$html = '<a href="#" class="cp-links-url">A link</a>';
if( strpos($html,'a.cp-links-url') ){
$company_crawler->filter('a.cp-links-url')->attr('href');
}
?>
Hi,
You could print the crawler to see if you have this href beacause I have the same problem but when I see the crawler I understand that I'm trying to select the erronous href
Hi , I have this error when using pjax what can I do?
Hi i have this error but I try the before code, but dont work for me 👎 Hi have this code: (when read one page with any pages) $table_details->children()->filter('tr')->each(function ( $col ){}); but when this dont see this filter in the list say this error (The current node list is empty), and I try validate to omit this or break, but dont work? I print the html code and the any table rows have th , how omit this?
Hi all. Maybe this is not relevant, but my solution is to check the nodes. $crawler->filter returns a Crawler, it has a count() method which returns the number of node.
$data= $company_crawler->filter('a.cp-links-url')->attr('href');
$result= $data->count() ? $data->text() : 0;