今天突然想采集点东西,刚开始还可以,一切正常,可是过了一段时间就什么也采集不到了,不知道问题出在哪里了,代码如下,请教各位?
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();PHPCurl信息采集模拟浏览器采集

解决方案 »

  1.   

    比如说这个地址:http://movie.douban.com/subject/10604486/?from=playing
      

  2.   

    如果可以试试把这个地址的内容采下来:http://www.tianya.cn/43064769,本来只想要一些搞笑的内容的,后来连页面都打不开了
      

  3.   

    你先计算下中间不停大概多久被封,然后设置停止时间。用usleep或者sleep控制。或者用代理ip吧,我现在也在采集,感觉停顿采集效率会低很多。