QQ咨询 官方微信

添加微信好友

官方小程序

百度小程序

微信小程序

头条小程序

关于我们

PHPCMS

修复phpcms自带采集无法采集https网站内容

 admin  2022-06-03 19:33:03
无法采集https的网站内容主要是https不支持file_get_contents获取内容,所以可以考虑采用curl的方式获取。(需要开启curl,可以在pathinfo里边查看)

(1)打开phpcms\modules\collection\classes\collection.class.php
在类里边添加新函数:
  1. protected static function curl_request($url){   
  2.         if (!function_exists('curl_init')) {   
  3.             throw new Exception('server not install curl');   
  4.         }   
  5.         $ch = curl_init(); 
  6.         curl_setopt($ch, CURLOPT_URL,$url); 
  7.         curl_setopt($ch, CURLOPT_HEADER,0); 
  8.         curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);//禁止调用时就输出获取到的数据 
  9.         curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1); 
  10.         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false); 
  11.         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,false); 
  12.         $result = curl_exec($ch); 
  13.         curl_close($ch); 
  14.         return $result; 
  15.     }   

(2)找到函数function get_htm把该函数
  1. protected static function get_html($url, &$config) { 
  2.         if (!empty($url) && $html = @file_get_contents($url)) { 
  3.             if ($syscharset != $config['sourcecharset'] && $config['sourcetype'] != 4) { 
  4.                 $html = iconv($config['sourcecharset'], CHARSET.'//TRANSLIT//IGNORE', $html); 
  5.             } 
  6.             return $html; 
  7.         } else { 
  8.             return false
  9.         } 
  10.     } 
改成
  1. protected static function get_html($url, &$config) { 
  2.         if(substr(trim($url),0, 5) == "https"){
              $html = @self::curl_request($url);
          }else{
             $html = @file_get_contents($url);
           }
  3.         if (!empty($url) && $html) { 
  4.             if ($syscharset != $config['sourcecharset'] && $config['sourcetype'] != 4) { 
  5.                 $html = iconv($config['sourcecharset'], CHARSET.'//TRANSLIT//IGNORE', $html); 
  6.             } 
  7.             return $html; 
  8.         } else { 
  9.             return false
  10.         } 
  11.     } 
然后保存即可获取,测试结果



不知道是否还有其他bug,欢迎留言反馈!
¥ 打赏
×
如果您觉得文章帮助了您就打赏一下吧
非常感谢你的打赏,我们将继续分享更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫打赏

微信扫一扫打赏

本文《修复phpcms自带采集无法采集https网站内容》发布于石头博客文章,作者:admin,如若转载,请注明出处:https://www.pweb123.com/cms/phpcms/745.html,否则禁止转载,谢谢配合!

文章点评

我来说两句 已有0条评论
点击图片更换

添加微信好友

添加微信好友

微信小程序

百度小程序