天天看點

PHP自動抽取論壇内容

統計結果:

1、CU:最後統計的空間浪費結果是:2282M end time:2010-04-04 11:38:40, 主題: 351641, 文章: 1432244, 會員: 23633797,建立于2003-2-10

2、化工:最後統計的空間浪費結果是:88M end time:2010-04-05 8:52:40, 主題: 3548, 文章: 9608, 會員: 19094,建立于2007-2-4

3、人大經濟論壇:今日: 1216, 昨日: 11562, 最高日: 16583

, 主題: 585770, 文章: 4881335, 會員: <b>1721538</b>,建立于2004-5-23

<b>4、起點手機論壇,http://www.dimboy.cn/index.php,</b>

今日: 1687, 昨日: 8143, 會員: 44822

<b>5、我要玩手機論壇,http://bbs.512530.com/512530.php,</b>今日: 2201, 昨日: 12656, 會員: 4048683

<b></b>

第一版:[2010-3-31]

&lt;?php     

$url = "http://linux.chinaunix.net/bbs/thread-1128442-1-1.html";

$ch = curl_init();

$timeout = 5;

$sum = 0;

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);

$contents = curl_exec($ch);

curl_close($ch);

 $path = '/tmp';

 $p = opendir($path);

 if(is_dir($path)){

    chdir($path);

     echo scandir($p);

    $ereg = '.*';

    ereg($ereg,$contents,$outcome);

      print_r($outcome);

//    foreach($outcome as $string)

//        echo $string.'

';

        //$sum += strlen($string);

    file_put_contents(web,$sum);

 }else

 echo "$path is not dir";

 closedir($path);

?&gt;

第二版:[2010-4-1]

&lt;?php

  define("CU","http://linux.chinaunix.net/bbs/forum-64-");

 // $url = "http://linux.chinaunix.net/bbs/thread-1128442-1-1.html";

 //判斷網頁連結是否已經到頭[未完成!]

  function isLinkEnd($url1,$url2){

      $page1 = file_get_contents($url1);

      $page2 = file_get_contents($url2);

      $startword = '';

      $endword = '';

      $startpos1 = strpos($page1,$startword);

      $endpos1 = strpos($page1,$endword);

      $startpos2 = strpos($page2,$startword);

      $endpos2 = strpos($page2,$endword);

      $result1 = strstr($page1,$startpos1+strlen($startword),$endpos1-$startpos1-$strlen($startword));

      $result2 = strstr($page2,$startpos2+strlen($startword),$endpos2-$startpos1-$strlen($startword));

      return ($result1 == $result2?0:1);

    }

  //自動抽取chinaunix.net上含有回複下載下傳的所有連結,儲存為數組傳回[已完成!]

  function linksOf(){

      $page = 1;

      $thisurl = CU."$page".'.html';

      while( $page             $links1[] = $thisurl;

            $page++;

            $thisurl = CU."$page".'.html';

      }

      return $links1;

    //自動檢查所有連結的分頁頁面位址,儲存為數組傳回[已完成!]

    function linksOfPart($links1){

        foreach($links1 as $linksBefore){

            $contents = file($linksBefore);

   //判斷網頁連結是否已經到頭[已完成!]

    function isLinkEnd($url1,$url2){

        $page1 = file_get_contents($url1);

        $page2 = file_get_contents($url2);

        $startword = '';

        $endword = '';

        $startpos1 = strpos($page1,$startword);

        $endpos1 = strpos($page1,$endword);

        $startpos2 = strpos($page2,$startword);

        $endpos2 = strpos($page2,$endword);

        $result1 = substr($page1,$startpos1+strlen($startword),$endpos1-$startpos1-strlen($startword));

        $result2 = substr($page2,$startpos2+strlen($startword),$endpos2-$startpos1-strlen($startword));

        //傳回0說明到頭,傳回1尚未到頭

        return ($result1 == $result2?0:1);

      $page = 1;

      $thisurl = CU."$page".'.html';

      while( $page             $links1[] = $thisurl;

            $page++;

            $thisurl = CU."$page".'.html';

      }

      return $links1;

        foreach($links1 as $linksBefore){

            $contents = file($linksBefore);

這一版本中,自動截取CU下載下傳版塊頁面,統計空間浪費功能已經實作,但程式運作速度很慢,有待改進。

出現錯誤:

開始時間:2010-04-02 09:37:19

<b>Notice</b>: Undefined variable: sum in <b>/var/www/html/lk.php</b>

on line <b>94</b>

<b>Fatal error</b>: Maximum execution time of 30 seconds exceeded in <b>/var/www/html/lk.php</b>

on line <b>75</b>

進一步改進:

    define("CU","http://linux.chinaunix.net/bbs/forum-64-");

    define("CU_F","http://linux.chinaunix.net/bbs/thread-");

準備再次改進:

直接抓取baidu.com的結果,"site:xxx.com 本帖隐藏的内容需要回複才可以浏覽"。

再進行分析,統計數量。

選取的網站有:

1、www.chinaunix.net  -&gt; 1000

2、http://bbs.chemdown.cn  -&gt; 290

3、http://www.kaoyansky.cn  -&gt; 242

4、http://www.pinggu.org  人大經濟論壇  -&gt; 932

5、http://www.tianya.cn  天涯社群  -&gt; 1080

6、bbs.duowan.com 多玩遊戲論壇 -&gt; 80400 -&gt; 主題: 3516513, 文章: 79036761, 會員: 8861576 -&gt; 2005-6-29

<b>7、sohu.com 搜狐網 -&gt; </b>9,490

8、sina.com.cn 新浪網 -&gt; 29100

9、mop.com 貓撲 -&gt; 155

        $endword = '';

        $startpos1 = strpos($page1,$startword);

        $endpos1 = strpos($page1,$endword);

        $startpos2 = strpos($page2,$startword);

        $endpos2 = strpos($page2,$endword);

        $result1 = substr($page1,$startpos1+strlen($startword),$endpos1-$startpos1-strlen($startword));

        $result2 = substr($page2,$startpos2+strlen($startword),$endpos2-$startpos1-strlen($startword));

        //傳回0說明到頭,傳回1尚未到頭

        return ($result1 == $result2?0:1);

  function linksOf($thisurl,$pagetotal){

      while( $page             $links1[] = $thisurl."$page".'.html';

            $flag = 0;

            while(count($contents = file($linksBefore)) == 0){

                    $flag++;

                    if($flag &gt; 3)break;

            }

            if($flag &gt; 3)continue;

閱讀(1470) | 評論(0) | 轉發(0) |

給主人留下些什麼吧!~~

評論熱議

請登入後評論。

Copyright 2001-2010 ChinaUnix.net All Rights Reserved 北京皓辰網域網絡資訊技術有限公司. 版權所有

感謝所有關心和支援過ChinaUnix的朋友們

京ICP證041476号 京ICP證060528号