千家信息网

如何解决phpcms v9采集功能无法使用的问题

发表于:2025-12-02 作者:千家信息网编辑
千家信息网最后更新 2025年12月02日,这篇文章主要介绍如何解决phpcms v9采集功能无法使用的问题,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!phpcms v9 采集功能 不能用怎么办?无法采集https的网
千家信息网最后更新 2025年12月02日如何解决phpcms v9采集功能无法使用的问题

这篇文章主要介绍如何解决phpcms v9采集功能无法使用的问题,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

phpcms v9 采集功能 不能用怎么办?

无法采集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;         }     }

然后保存即可获取,测试结果

不知道是否还有其他bug,欢迎留言反馈!

以上是如何解决phpcms v9采集功能无法使用的问题的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注行业资讯频道!

0