如题:file_get_contents不能用,不太稳定。有没有其它方法?

解决方案 »

  1.   

    用scoket 获取到header头后 即关闭连接
    如果说要更智能的话 就再通过header头中显示的body大小来判断是否要获取body
    当然如果只字需要header那很简单 http协议中有header的方法 直接发送一个header请求就是,服务器不会返回body
      

  2.   

    $ch = curl_init();// set URL and other appropriate options
    curl_setopt($ch, CURLOPT_URL, "http://www.baidu.com/");
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_NOBODY, true);
    // grab URL and pass it to the browser
    curl_exec($ch);// close cURL resource, and free up system resources
    curl_close($ch);
      

  3.   

    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回$header=curl_exec($ch);
    //执行正则匹配$header
    // close cURL resource, and free up system resources
    curl_close($ch);
      

  4.   

    我描述错误了,是要title keyword description这些内容body中的不要,这个代码抓回来是网页的基本信息吧
      

  5.   

    也就是说当采集到description就停止采集?具体该怎么做呢?在线等!
      

  6.   

    本帖最后由 xuzuning 于 2012-09-14 09:33:53 编辑