PHP头条
热点:

php信息采集采不到内容?该如何解决


php 信息采集 采不到内容?
今天突然想采集点东西,刚开始还可以,一切正常,可是过了一段时间就什么也采集不到了,不知道问题出在哪里了,代码如下,请教各位?
function getContent($url) {
        $url = trim($url);
        $content = '';
        if (extension_loaded('curl')) {
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
            curl_setopt($ch, CURLOPT_HEADER, 0);
            curl_setopt($ch,CURLOPT_HTTPHEADER,array(
         'Accept-Language: zh-cn',
         'Connection: Keep-Alive',
         'Cache-Control: no-cache'
     ));
       $user_agent ="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)";       
        curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
            $content = curl_exec($ch); 
            curl_close($ch);
        } else { 
            $content = file_get_contents($url);
        }
        return trim($content);

    }//end func getContent(); PHP Curl 信息采集 模拟浏览器采集 分享到:
------解决方案--------------------
你采集的url是什么
------解决方案--------------------

www.phpzy.comtrue/phprm/7480.htmlTechArticlephp信息采集采不到内容?该如何解决 php 信息采集 采不到内容? 今天突然想采集点东西,刚开始还可以,一切正常,可是过了一段时间就什么也采集不到了,不知道问题出在哪里了,代...

相关文章

相关频道:

PHP之友评论

今天推荐