phpweb-scrapingurlsimple-html-dom

php getting error from simplehtmldom when trying to get next page of url web scrape


I am trying to get the next page of the topic but it gives an error. Is there any way to avoid that error to be able to scrape the next page within that age topic? (next page goes by 20 and after is 40 and so forth) The error is given below and I'm sure someones going to request me to put the code up but not sure how much or what code I should post up.

http://blah.com/quotes/topic/age 20 1 1http://blah.com/quotes/topic/age/20

Fatal error: Call to a member function find() on a non-object in /Users/blah/Sites/simple_html_dom.php on line 879

UPDATE***

this is the line between 870-885

 function save($filepath='') {
        $ret = $this->root->innertext();
        if ($filepath!=='') file_put_contents($filepath, $ret, LOCK_EX);
        return $ret;
    }

    // find dom node by css selector
    // Paperg - allow us to specify that we want case insensitive testing of the value of the selector.
    function find($selector, $idx=null, $lowercase=false) {
        return $this->root->find($selector, $idx, $lowercase);
    }

    // clean up memory due to php5 circular references memory leak...
    function clear() {
        foreach ($this->nodes as $n) {$n->clear(); $n = null;}

Solution

  • The first thing that you should check is your file where the $html->find() is called.

    1. Check if you included simple_html_dom.php(with an include) at the beginning of the file
      -make sure it is there
      -make sure the path is correct

    2. Check if you have this line: $html = file_get_html('http://www.google.com/');
      -of course your line will have the web address you are trying to get

    I think the problem is that you might have not included simple_html_dom or that you are missing the file_get_html.

    Check those. The problem is not in simplehtmldom.php so just look at the file you created.

    Good luck!

    UPDATE
    While your at it. Please provide the source in your file, or at least the line where you call find().