php - Scrape HTML & count children using Simple HTML DOM -


i'm trying collect data website, , want count amount of elements in element. targeting different dom elements works fine, reason $count variable in example below stays @ "0". i'm missing silly, can't seem find it.

the html on website follows:

<div id="list_options">     <div class="list_mtgdef_option pointer">         <div class="list_mtgdef_foildesc shadow">         </div>         <div class="list_mtgdef_stock tooltip">             <div class="list_mtgdef_stock_left">                 <span class="foil008469_1 block  "></span>                 <span class="foil008469_2 block  transparency_25"></span>             </div>             <div class="list_mtgdef_stock_right">                 <span class="008469_8 block  "></span>                 <span class="008469_7 block  "></span>                 <span class="008469_6 block  "></span>                 <span class="008469_5 block  "></span>                 <span class="008469_4 block  "></span>                 <span class="008469_3 block  "></span>                 <span class="008469_2 block  "></span>                 <span class="008469_1 block  "></span>             </div>         </div>     </div> </div> 

and php i'm using:

$array = array();  foreach($html->find('#list_options .list_mtgdef_option') $element) {     $count = 0;      foreach($element->find('.list_mtgdef_stock', 0)->childnodes(1)->childnodes $node) {         if(!($node instanceof \domtext))             $count++;     }      $row = array(         'stock' => strval($count)     );      array_push($array, $row);  } echo json_encode($array); 

you can do:

count($element->find('.list_mtgdef_stock > *[2] > *')) //=>8 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -