想用php实现网页抓取,怎么实现啊

解决方案 »

  1.   

    简单的: file_get_contents()
    复杂且强大的: curl 
      

  2.   

    一:采集类库,snoopy.class.php。下载:(http://www.php100.com/html/download/pl/2013/0111/9090.html)说起做网站对大部分站长来讲,采集是必不可缺的部分。很多站长可能直接使用dedecms之类cms内置的采集功能了,但是有时候网站很小没必要使用cms或者cms的内置采集功能满足不了我们的需求的时候怎么办呢。那就可以使用这个采集类库了。使用方法非常简单。
    使用演示://加载类库文件include("snoopy.php");//要采集的页面地址$url = "http://www.www.shlongyingjixie.com";  $snoopy = new Snoopy;//去抓取页面$snoopy->fetch($url);//输出抓回页面的html  echo $snoopy->results;接下来,用正则表达式把你需要的内容匹配出来。这样采集就大功告成了。简单吧!
      

  3.   

    如果你要抓取的网站没有任何限制的话 就用 file_get_contents 然后用正则表达式选出你要用的内容
    否则 你就要用curl抓取了 (可以使用代理,可以使用cookie等等)
      

  4.   

    http://topic.csdn.net/u/20080824/07/0125890f-9a98-4296-ad84-c5c748c17581.html
      

  5.   

    PHP多线程比较难实现,效率也不高,我是用python来实现的,原理都一样,都是通过正规来获取内容的
      

  6.   


    python那效率也不行,特别是处理中文字符之类的。
    我感觉还是桌面程序那种速度快很多。
      

  7.   


    function func_ReadPage($strUrl, $nTimeOut = 0, $nReRead = 2) //读网页内容 $nReRead-2 最多读网页两次
    {
    //$nTimeOut = 0 不设读页面最长时间
    //$nTimeOut不为0时, $nReRead才有效, $nReRead = 2默认最多读两次

    if($nReRead == 0)
    return 0;
    $nReReadTem = $nReRead - 1;
    if($nTimeOut == 0)
    {
    if(!$fp = @fopen($strUrl, "r"))
    return 0;
    if(!$strPage = stream_get_contents($fp)) //file_get_contents
    {
    fclose($fp);
    return 0;
    }
    fclose($fp);
    return $strPage;
    }

    //当$nTimeOut不为0时
    $opts = array('http'=>array('method'=>"GET",'timeout'=>$nTimeOut));
    $context = stream_context_create($opts);
    $strPage = @file_get_contents($strUrl, false, $context); if(strlen($strPage) < 10)
    return func_ReadPage($strUrl, $nTimeOut, $nReReadTem);

    return $strPage;
    }
    ///////////////////////////////////////////////////////echo func_ReadPage("http://www.baidu.com");