flapane
flapane

Reputation: 543

simple_html_dom: Call to a member function find() on a non-object in

This code has been working good for months. The output consisted of a few lines containing statistics for a given username. The website from which the html page is taken is not down, and the content of the page in file_get_html hasn't changed. All of a sudden (I checked and nobody modified it) it stopped working. Here's the relevant part:

[...]if ($FileAge > ($expiretime * 60) || 0 == filesize($cachename))
{
    include_once('simple_html_dom.php');
    $html = file_get_html('http://www.foo.com/search?what=user%3A'.YOUR_USER.'&search=Search');
    var_dump($html); //TEST
    $link = $html->find('.likeh4 lightGrey.', 0)->find('a', 0)->href;   // Get the last activity link
[...]

The error log says:

[02-Feb-2013 17:02:19 Europe/Berlin] PHP Fatal error:  Call to a member function find() on a non-object in /foo.php on line 22 (the line with $link).

var_dump($html) gives bool(false)

I have a similar script which parses an html page from another website. It stopped working as well.

[...]include_once('simple_html_dom.php');
$html = file_get_html('http://my.flightmemory.com/'.FLIGHTMEMORY_USER);
$chilometri_table = $html->find('table', 2);    [...]

I tried to save on my webserver one of those html pages and I don't get such error. Did my host disable some php function for security reasons? (actually, file_get_html comes from simple_html_dom and not from php native functions)

Any hints? Thanks

Upvotes: 0

Views: 1959

Answers (2)

Seeker313
Seeker313

Reputation: 1

If you try to get [href] I had same problem and fixed it. need valid it's a simple_html_dom_node

if(is_a($html->find('.likeh4 lightGrey. a', 0),'simple_html_dom_node' )
  $link = $html->find('.likeh4 lightGrey. a', 0)->href;

OR

foreach ( $$html->find('.likeh4 lightGrey. a') as $links ) {
 $link =$links->href;
}

Upvotes: 0

undone
undone

Reputation: 7888

It is probably way too late but:
Simple_html_dom has a constant to check given html size - MAX_FILE_SIZE. by default it's 600KB. It's enough for most cases, but if your given html is bigger than that, it will fail and returns false and causes that fatal error.

Upvotes: 1

Related Questions