繁体   English   中英

DOM不打印id的nodeValue

[英]DOM not printing nodeValue of an id

我正在打印Google加上Google网站的份额计数。 我的编码:

$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 但是,当您直接读取字符串时却没有。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM