Pregunta

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 ?

¿Fue útil?

Solución

try this:

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

Otros consejos

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>';
   }
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top