DOM不打印id的nodeValue

时间:2014-12-17 10:12:06

标签: javascript php dom

我正在打印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>";

1 个答案:

答案 0 :(得分:1)

在执行strtolower时,您在HTML上使用file_get_contents。但不是直接读到字符串的时候。