>  기사  >  백엔드 개발  >  php 信息采集 采不到内容?该如何解决

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

WBOY
WBOY원래의
2016-06-13 12:43:491165검색

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 信息采集 模拟浏览器采集
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.