api - domcrawler loop and if statement to check if class exists -


hi i'm running little problem domcrawler. i'm scraping page , has div class of .icon3d. want go through page , every div class add "3d" item array, , every div without add "2d" item. here code have far.

for ($i=0; $i < 10; $i++) {      $divs =  $crawler->filter('div.icon3d');         if(count($divs)){             $type[] = '3d';         }else{             $type[] = '2d';         }     } 

check the domcrawler component documentation first. filter method returns filtered list of nodes, calling ->filter('div.icon3d') returned value list of div elements have icon3d class.

first need find div elements, loop through them , add either 3d or 2d array depending on icon3d css class existance.

$divs = $crawler->filter('div'); foreach ($divs $node) {     $type[] = (false !== strpos($node->getattribute('class'), 'icon3d')) ? '3d' : '2d'; } 

update

$crawler->filter('a')->each(function(crawler $a) {     $div = $a->filter('div');     // div exists     if ($div->count()) {      } }); 

to crawler node class use

$div->getnode(0)->getattribute('class') 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -