溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

phpcms無法采集的解決方法

發(fā)布時間:2020-08-20 10:31:11 來源:億速云 閱讀:158 作者:小新 欄目:建站服務(wù)器

phpcms無法采集的解決方法?這個問題可能是我們?nèi)粘W(xué)習(xí)或工作經(jīng)常見到的。希望通過這個問題能讓你收獲頗深。下面是小編給大家?guī)淼膮⒖純?nèi)容,讓我們一起來看看吧!

phpcms無法采集怎么辦?

無法采集https的網(wǎng)站內(nèi)容主要是https不支持file_get_contents獲取內(nèi)容,所以可以考慮采用curl的方式獲取。(需要開啟curl,可以在pathinfo里邊查看)

(1)打開phpcms\modules\collection\classes\collection.class.php

在類里邊添加新函數(shù):

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);//禁止調(diào)用時就輸出獲取到的數(shù)據(jù) 
        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)找到函數(shù)function get_htm把該函數(shù)

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

然后保存即可獲取,測試結(jié)果

phpcms無法采集的解決方法

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

感謝各位的閱讀!看完上述內(nèi)容,你們對phpcms無法采集的解決方法大概了解了嗎?希望文章內(nèi)容對大家有所幫助。如果想了解更多相關(guān)文章內(nèi)容,歡迎關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI