In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
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; } }
然后保存即可获取,测试结果
Don't know if there are any other bugs, welcome to leave a message!
Thank you for reading! After reading the above content, do you know about the solution that phpcms cannot collect? I hope the content of this article is helpful to everyone. If you want to know more about related articles, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.