2013-04-23 61 views
0

我使用簡單的HTML DOM解析器刮產品從一個網站,我寫了下面的代碼爲這個PHP:網頁加載無限的時間

<?php 
    error_reporting(E_ALL); 
    require_once('lib/simple_html_dom.php'); 
    set_time_limit(0); 
    ini_set('memory_limit', '1024M'); 
    ini_set('max_input_time ', '99999'); 
    $url='http://www.yourpoolhq.com/pool-supplies/aboveground/pool-liners/round/unibead.html'; 
    $html = file_get_html($url); 

    if(is_object($html)){ 
     foreach ($html->find('div.category-products') as $elem){ 

      $data = $elem->innertext; 
      $strdata = str_get_html($data); 
      foreach ($strdata->find('a') as $a) { 
        if($a->plaintext!=''){ 
         get_detail_page($a->href); 
         flush(); 

        } 
        flush(); 
      } 
      unset($data); 
      unset($strdata); 
     } 
     $html->clear(); 
     unset($html); 
    } 

    function get_detail_page($href){ 
    $details = file_get_html($href); 
     if(is_object($details)){ 

      foreach ($details->find('h1') as $ess) { 
           //print_r($ess); this has data 
       echo $ess->plaintext; // not getting this, Why this is not printing. x-(               
       flush();  
      } 
      $details->clear(); 
      unset($details); 
     } 
    flush();  
} 


    ?> 

沒有得到什麼錯誤我在做什麼在這裏。任何想法的傢伙。

編輯:我已經更新了代碼在某些地方添加刷新並評論錯誤部分。

+0

向我們展示您的file_get_html()? – bwoebi 2013-04-23 17:43:16

+0

它的功能simple_html_dom.php http://simplehtmldom.sourceforge.net – ravisoni 2013-04-23 17:50:32

+0

清除一個垃圾代碼,看看是否有效。並添加每一塊代碼,看看是什麼導致問題 – Reshad 2013-04-23 17:42:36

回答

0

你的代碼本身沒有任何明顯的缺陷。我能想到的唯一的事情是file_get_html由於您的服務器和somedomain.com上的遠程服務器之間的延遲而花費了很長時間。通過延遲工具(在您使用PHP的服務器上執行tracert,ping等)可能是值得研究的。

+0

你可能是正確的,但是當我嘗試直接調用get_detail_page($ url)這是正常工作,但是當我把它放在循環中的上面的代碼,它開始惱怒我mozilla說:連接被重置 – ravisoni 2013-04-23 18:13:16

+0

@ravisoni:好吧,所以,如果它是工作時,你手動提供$ url,我猜這是要麼中間請求超時,要麼b。它收到的URL格式不正確,請問你們可以調查兩個嗎?(另外,對於怯懦而不離開原因的懦夫 - 總是讚賞) – 2013-04-23 20:18:04

+0

檢查代碼現在幾乎完成,但文本沒有得到:'( – ravisoni 2013-04-23 20:25:20