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