0

我正在使用简单的 html dom 解析器从网站上抓取产品,我为此编写了以下代码

    <?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();    
}


    ?>

没有得到我在这里做错了什么。任何想法的家伙。

编辑:我已经更新了在某些地方添加的代码并注释了错误部分。

4

1 回答 1

0

您的代码本身没有任何明显的缺陷。我唯一能想到的是file_get_html由于您的服务器和 somedomain.com 上的远程服务器之间的延迟而需要很长时间。可能值得通过延迟工具(您使用 PHP 的服务器上的跟踪、ping 等)进行调查。

于 2013-04-23T17:46:57.017 回答