javascript - DOM 不打印 id 的 nodeValue

标签 javascript php dom

我正在打印 Google plus 谷歌网站的分享计数。我的编码:

$dom = new DOMDocument();
$html = strtolower(file_get_contents("https://plusone.google.com/u/0/_/+1/fastbutton?count=true&url=http://google.com"));
libxml_use_internal_errors(true);
$dom->loadHTML($html);
libxml_clear_errors();
echo $dom->getElementById('aggregateCount')->nodeValue;

我得到这个输出:

Notice: Trying to get property of non-object in C:\xampp\htdocs\start\test.php on line 7

当我直接传递这个html时,它就工作了。

$html = "<html><head></head><body><div id='aggregateCount'>node value</div></body></html>";

最佳答案

在执行 file_get_contents 时,您可以在 HTML 上使用 strtolower。但当您直接读取字符串时则不然。

关于javascript - DOM 不打印 id 的 nodeValue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27523099/

相关文章:

javascript - Nodejs Server 有没有可以集成的第三方推送服务?

javascript - bootstrap.css 和 IE11 问题

php - 带有 Laravel Excel : Your requirements could not be resolved to an installable set of packages 的 Laravel 7

php - 服务器返回空白页和 200 OK

javascript - 如何检查 document.getElementById 是否给出空结果?

android - 如何在Android中制作GPX文件

javascript - ng-repeat 与项目数组不一致

javascript - Chrome扩展如何每2秒运行一次后台文件功能

php - moodle的视频插件

javascript - 使用 JavaScript 删除特定的 <li> 元素