Question

I have div, and want get 7,89 number, my selector is

<div class="titlePageSprite star-box-giga-star"> 7,89 </div>

$ret['Rating'] = $html->find('div.star-box-giga-star')->content;

but I get empty array, what I doing wrong ?

Was it helpful?

Solution

try this:

$ret['Rating'] = $html->find('div.star-box-giga-star', 0)->innertext;

OTHER TIPS

find() returns a DOMNodeList of ALL elements that match the find parameters, even if there's only one (or none) matching elements. You can tell it specifically which node to return via an optional parameter:

$rating = $html->find('div.star-box-giga-star', 0)
                                              ^^^^---return 1st node (0-based)

or something silly-ish like

$nodes = $html->find(...);
foreach($nodes as $node) {
     $rating = $node->content;
     break;
}

Use XPath directly instead:

   foreach($xpath->query('//div[contains(@class, "star-box-giga-star")]') as $rating) {
      echo $rating->nodeValue, '<br>';
   }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top