【问题标题】:How can I get the span tag value using php curl and simple html dom parser?the exact value does not show如何使用 php curl 和简单的 html dom 解析器获取 span 标签值?未显示确切值
【发布时间】:2019-02-15 13:02:57
【问题描述】:

代码:

  <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 | number}} 但我想要 304,575

【问题讨论】:

  • 什么也没显示

标签: php curl web-scraping simple-html-dom


【解决方案1】:

它对我有用:

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
}

【讨论】:

  • 我帮不了你,但我试过了,它对我有用。
【解决方案2】:

你可以使用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

参考:-https://stackoverflow.com/a/6366390/4248328

【讨论】:

  • 但是当我应用相同的逻辑时,我的输出不会改变。 eval.in/1056204 这是我的代码。谢谢
  • @JalisMahamud 您使用的平台不支持CURL。尝试在你最后运行代码并检查
  • @JalisMahamud 请用您的 curl 代码、错误描述以及您想要的预期结果提出一个新问题。你肯定会得到帮助
猜你喜欢
  • 1970-01-01
  • 2016-01-08
  • 1970-01-01
  • 2019-01-20
  • 1970-01-01
  • 2011-03-22
  • 2013-06-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多