Php采集网无法采集,phpcms无法采集怎么办

808871d18735e2da249472ad7d8a0d5c.png

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;

}

}

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

f9f6fdaf83ca8c8f7cb505d3066c95ab.png

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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值