I'm creating a web crawler and I have a problem with the "find" function. When I load "https://maps.google.com" $page will be true, but "find" will give me a fatal error, precisely:
"Fatal error: Call to a member function find() on a non-object in C:*\simple_html_dom.php on line 1113"
Here is the code:
$page->load_file($url); // "https://maps.google.com"
if($page && is_object($page) && isset($page->nodes)) {
if (method_exists($page,"find")) { if ($page->find("html")) { $t = $page->find("title", 0); if($t){ $title = $t->innertext; } } }
}
How could I filter webpages like the one above to prevent my script from stopping?
"Fatal error: Call to a member function find() on a non-object in C:*\simple_html_dom.php on line 1113"
This error indicates, that page loading was not successful and $page is probably null (because it couldn't load the page). You need to account for that:
if($page){ /* parse contents */ } else { /* error */ }
Your solution does the same thing in a awkward way by checking if $page is actually the object instead of checking if $page is null.
I'll close this issue because it is quite old and probably of no concern anymore. Please don't hesitate to open a new ticket for futher discussion.