未定义函数 load_file() 简单 html dom 库

undefined function load_file() simple html dom library

我想使用简单 HTML DOM 库从网站上抓取内容。我正在编写脚本的第一页包含标题和文章内容的 links。所以我想应用的逻辑是我从第一页获取 links,然后从每个 link 指向的每个页面获取内容。我在第二个 load_file.

中收到 undefined function load_file() 错误
   <?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Crawler extends Frontend_controller {

    public function __construct(){

        parent::__construct();
        require_once(APPPATH . 'libraries/simple_html_dom.php');

    }

    public function index(){

        $target_url = "https://example.com/";
        $html = new simple_html_dom();
        $html->load_file($target_url);
        foreach($html->find('article') as $post){
            $title = $post->find('h1 a', 0)->innertext;
            $link = $post->find('h1 a', 0);
            //echo $title."<br />";
            //echo $link->href."<br />";
            $sample_html = new simple_html_dom();
            $sample_html = load_file($link->href);
            foreach ($sample_html->find('p') as $content) {

                echo $content;
            }


        }

    }//end method

}//end class

改变

  $sample_html = load_file($link->href);

   $sample_html->load_file($link->href);