0

シンプルなhtml domパーサーを使用してWebサイトから製品をスクレイピングしています。このために次のコードを作成しました

    <?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 を使用しているサーバーの tracert、ping など) を使用して調査する価値があるかもしれません。

于 2013-04-23T17:46:57.017 に答える