phpcms无法采集怎么办

来源:undefined 2024-12-30 13:40:12 1032

phpcms无法采集怎么办?

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

(1)打开phpcmsmodulescollectionclassescollection.class.php

在类里边添加新函数:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

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把该函数

立即学习PHP免费学习笔记(深入)”;

1

2

3

4

5

6

7

8

9

10

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; 

}

登录后复制

改成

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

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,欢迎留言反馈!

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

最新文章