0
我想使用簡單的HTML DOM庫從網站上刮取內容。我正在做我的腳本的第一頁包含標題和文章內容的鏈接。所以我想要應用的邏輯是我從第一頁獲得鏈接,然後從每個鏈接指向的每個頁面獲取內容。我得到未定義的函數load_file()在第二個load_file中的錯誤。未定義的函數load_file()簡單的html DOM庫
<?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