Home  >  Article  >  Backend Development  >  php 信息采集 采不到内容?该如何解决

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

WBOY
WBOYOriginal
2016-06-13 12:43:491163browse

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 信息采集 模拟浏览器采集
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn