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