Вопрос

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 ?

Это было полезно?

Решение

try this:

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

Другие советы

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>';
   }
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top