2013-03-31 40 views
0

我正在使用「simple_html_dom.php」從維基百科網站中刪除數據。如果我運行scraperwiki.com中的代碼,它會拋出一個錯誤,如退出狀態139,並且如果在我的xampp服務器中運行相同的代碼,服務器將掛起。simple_html_dom.php

  1. 我有一組鏈接
  2. 我試圖從所有的網站得到素養
  3. 如果我運行一個鏈接的代碼是沒有問題的,它的返回預期的結果
  4. 如果我嘗試,我所面臨的上述問題從一個全力以赴的網站獲取數據

的代碼是:

<?php 
    $test=array 
    ( 
    0 => "http://en.wikipedia.org/wiki/Andhra_Pradesh", 
    1 => "http://en.wikipedia.org/wiki/Arunachal_Pradesh", 
    2 => "http://en.wikipedia.org/wiki/Assam", 
    3 => "http://en.wikipedia.org/wiki/Bihar", 
    4 => "http://en.wikipedia.org/wiki/Chhattisgarh", 
    5 => "http://en.wikipedia.org/wiki/Goa", 

    for($ix=0;$ix<=9;$ix++){ 

    $content = file_get_html($test[$ix]); 
    $tables = $content ->find('#mw-content-text table',0); 
    foreach ($tables ->children() as $child1) { 
     foreach($child1->find('th a') as $ele){ 
     if($ele->innertext=="Literacy"){ 
       foreach($child1->find('td') as $ele1){ 
        echo $ele1->innertext; 
    }}} }} 

指導我哪裏錯了。有沒有內存問題?有沒有xampp配置?

+0

將函數中循環中的代碼換行。然後在循環內運行該函數。它會防止內存泄漏。 – 2013-03-31 12:08:05

+0

嘗試添加'set_time_limit($秒)' –

回答

0
<?php 
    require 'simple_html_dom.php'; 
    $test = array( 
    0 => "http://en.wikipedia.org/wiki/Andhra_Pradesh", 
    1 => "http://en.wikipedia.org/wiki/Arunachal_Pradesh", 
    2 => "http://en.wikipedia.org/wiki/Assam", 
    3 => "http://en.wikipedia.org/wiki/Bihar", 
    4 => "http://en.wikipedia.org/wiki/Chhattisgarh", 
    5 => "http://en.wikipedia.org/wiki/Goa"); 

    for($ix=0;$ix<=count($test);$ix++){ 
    $content = file_get_html($test[$ix]); 
    $tables = $content ->find('#mw-content-text table',0); 
    foreach ($tables ->children() as $child1) { 
     foreach($child1->find('th a') as $ele){ 
     if($ele->innertext=="Literacy"){ 
      foreach($child1->find('td') as $ele1){ 
      echo $ele1->innertext; 
      } 
     } 
     } 
    } 
    $content->clear(); 
    } 
?> 

但這些URL太多了。您可能會收到致命錯誤max execution time execeeded或者您可能得到error 324

+0

以上的代碼必須在for循環的結尾處添加以下代碼$ content-> clear(); – shivaP

相關問題