首頁 > CMS教程 > PHPCMS > 主體

phpcms無法採集怎麼辦

藏色散人
發布: 2019-12-28 10:06:31
原創
2484 人瀏覽過

phpcms無法採集怎麼辦

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; 
        } 
    }
登入後複製

然後儲存即可獲取,測試結果

phpcms無法採集怎麼辦

不知道是否還有其他bug,歡迎留言回饋!

PHP中文網,大量的免費PHPCMS教學,歡迎線上學習!

以上是phpcms無法採集怎麼辦的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!