简单的PHP Web搜寻器返回简单的HTML DOM错误

Ins*_*nct 0 php web-crawler

我有一个PHP脚本,可返回网页上的链接。我收到500内部错误,这就是我的服务器日志所说的。我让我的朋友在他的服务器上尝试相同的代码,它似乎可以正常运行。有人可以帮我调试我的问题吗?警告说有关包装器的信息已禁用。我检查了1081行,但没有看到allow_url_fopen

PHP警告:file_get_contents():在服务器配置中,http://包装器已被第1081行的/hermes/bosweb/web066/b669/ipg.streamversetv/simple_html_dom.php中的allow_url_fopen = 0禁用

PHP警告:file_get_contents(http://www.dota2lounge.com/):无法打开流:在第1081行的/hermes/bosweb/web066/b669/ipg.streamversetv/simple_html_dom.php中找不到合适的包装器

PHP致命错误:在/hermes/bosweb/web066/b669/ipg.streamversetv/sim中的非对象上调用成员函数find()

<?php
 include_once('simple_html_dom.php');
 $target_url = 'http://www.dota2lounge.com/';
 $html = new simple_html_dom();
 $html->load_file($target_url);
  foreach($html->find(a) as $link){
    echo $link->href.'<br />';
  }
?>
Run Code Online (Sandbox Code Playgroud)

小智 5

  1. 下载最新的simple_html_dom.php:链接下载

  2. 在您最喜欢的编辑器中打开simple_html_dom.php并将此代码添加到前几行(可以在之后添加<?php):

    function file_get_contents_curl($url) {
    
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_URL, $url);     
    
        $data = curl_exec($ch);
        curl_close($ch);
    
        return $data; }
    
    Run Code Online (Sandbox Code Playgroud)
  3. 查找行从function file_get_html($url.....我开始是第71行,但是您也可以在编辑器中使用搜索。(搜索file_get_html)

  4. 编辑此行(函数file_get_html之后的以下几行):

    $contents = file_get_contents($url, $use_include_path, $context, $offset);

    对此:

    $contents = file_get_contents_curl($url);

  5. 代替load_file,使用file_get_html,它会为您工作,而无需编辑php.ini