【发布时间】:2015-02-15 20:30:13
【问题描述】:
我正在打印 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>";
【问题讨论】:
-
$dom 不是对象,因此,它可能无法正确加载 html
-
file_get_contents是否成功返回您的 html?如果不是,则 dom 未加载到$html中,因此很想获得非对象的属性nodeValue。 -
放弃
strtolower电话
标签: javascript php dom