如何使用 php curl 和简单的 html dom 解析器获取跨度标记值?确切的值不显示

How can I get the span tag value using php curl and simple html dom parser?the exact value does not show

代码:

  <span class="file-count-label" ng-init="totalResultCount=304575" ng-show="totalResultCount" style="">304,575</span>

$videos=$html->find('span[class=file-count-label]');
foreach($videos as $e)
{
  echo $e->plaintext;
}

输出:{{totalResultCount |数}} 但我想要 304,575

您可以使用xpath selector

<?php

$html = '<span class="file-count-label" ng-init="totalResultCount=304575" ng-show="totalResultCount" style="">304,575</span>';
$doc = new DOMDocument;
$doc->loadHTML($html);
$finder = new DomXPath($doc);
$classname="file-count-label";
$videos = $finder->query("//*[contains(@class, '$classname')]");

foreach($videos as $e)
{
  echo $e->nodeValue;
}

输出:- https://eval.in/1056186

参考文献:-

对我有用:

include 'simple_html_dom.php';
$html = str_get_html('<span class="file-count-label" ng-init="totalResultCount=304575" ng-show="totalResultCount" style="">304,575</span>');

$videos=$html->find('span[class=file-count-label]');
foreach($videos as $e)
{
  echo $e->plaintext; 
  // 304,575
}