当前位置:首页站长学院PHPCMSphpcms v9 采集功能 不能用怎么办?
企业营销,就选知企PROSAAS

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; 
        } 
    }

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

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

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

PHP中文网,大量的免费PHPCMS教程,欢迎在线学习!

以上就是phpcms v9 采集功能 不能用怎么办?的详细内容,更多请关注知企PROSAAS其它相关文章!

温馨提示:

文章标题:phpcms v9 采集功能 不能用怎么办?

文章链接:https://ceshi.prosaas.cn/5419.html

更新时间:2020年01月10日

声明: 本站大部分内容均收集于网络!若内容若侵犯到您的权益,请发送邮件至:973664285@qq.com我们将第一时间处理! 资源所需价格并非资源售卖价格,是收集、整理、编辑详情以及本站运营的适当补贴,并且本站不提供任何免费技术支持。 所有资源仅限于参考和学习,版权归原作者所有,更多请阅读知企PROSAAS协议

给TA打赏
共{{data.count}}人
人已打赏
PHPCMS

phpcms如何配置数据库文件

2020-1-9 17:24:25

PHPCMS

phpcms v9注册不了怎么办?

2020-1-10 10:15:02

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索