Uncaught Error: Call to undefined function get_file_html()

Uncaught Error: Call to undefined function get_file_html()

我正在尝试解析此网页,当我在 include "simple_html_dom.php"; 之后包含 CURL 部分代码时它工作正常,但如果评论该部分并且仅使用 simple_html_dom 它会给我错误提示

未捕获错误:在 filepath\index 中调用未定义的函数 get_file_html()。php:18 堆栈跟踪:#0 {main} 在 filepath\index 中抛出。php

如果文件不在本地,我需要 curl 吗?

抱歉,如果这是一个菜鸟问题,我才刚刚开始 php。

<?php

    include "simple_html_dom.php";

    $html = new simple_html_dom();
    $html = get_file_html('https://in.tradingview.com/symbols/NSE-TCS/');

    foreach($html->find('a') as $element)
       echo $element->href . " -> " . $element->plaintext .'<br>'; 

?>

CURL

/*  $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://in.tradingview.com/symbols/NSE-TCS/");

    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    $response = curl_exec($ch);

    curl_close($ch);
    //echo $response;*/

P.S。我已经从 here 下载了 simple_html_dom.php,文件位于根目录

您可以将 str_get_html() 与您的 curl 请求的响应一起使用,因此代码看起来像...

include "simple_html_dom.php";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://in.tradingview.com/symbols/NSE-TCS/");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);

$html = str_get_html($response);
foreach($html->find('a') as $element)   {
    echo $element->href . " -> " . $element->plaintext .'<br>';
}