phpcms无法采集怎么办-PHPCMS

资源魔 41 0

phpcms无奈采集怎样办?

无奈采集https的网站内容次要是https没有支持file_get_contents猎取内容,以是能够思考采纳curl的形式猎取。(需求开启curl,能够正在pathinfo里边查看)

(1)关上phpcms\modules\collection\classes\collection.class.php

正在类里边增加新函数:

protected static function curl_request($url){   
        if (!function_exists('curl_init')) {   
            throw new Exception('server not install curl');   
        }   
        $ch = curl_init(); 
        curl_setopt($ch, CURLOPT_URL,$url); 
        curl_setopt($ch, CURLOPT_HEADER,0); 
        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);//制止挪用时就输入猎取到的数据 
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1); 
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false); 
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,false); 
        $result = curl_exec($ch); 
        curl_close($ch); 
        return $result; 
    }

(2)找到函数function get_htm把该函数

protected static function get_html($url, &$config) { 
        if (!empty($url) && $html = @file_get_contents($url)) { 
            if ($syscharset != $config['sourcecharset'] && $config['sourcetype'] != 4) { 
                $html = iconv($config['sourcecharset'], CHARSET.'//TRANSLIT//IGNORE', $html); 
            } 
            return $html; 
        } else { 
            return false; 
        } 
    }

改为

protected static function get_html($url, &$config) { 
        if(substr(trim($url),0, 5) == "https"){
          $html = @self::curl_request($url);
      }else{
         $html = @file_get_contents($url);
       }
        if (!empty($url) && $html) { 
            if ($syscharset != $config['sourcecharset'] && $config['sourcetype'] != 4) { 
                $html = iconv($config['sourcecharset'], CHARSET.'//TRANSLIT//IGNORE', $html); 
            } 
            return $html; 
        } else { 
            return false; 
        } 
    }

而后保留便可猎取,测试后果

4340a969f5d846d6210fc9d44045612.png

没有晓得能否另有其余bug,欢送留言反馈!

PHP中文网,年夜量的收费PHPCMS教程,欢送正在线学习!

以上就是phpcms无奈采集怎样办的具体内容,更多请存眷资源魔其它相干文章!

标签: phpcms phpcms教程 phpcms技巧 php问题解决

抱歉,评论功能暂时关闭!