我正在尝试从Google搜索中接收价格数据,并且此代码使我“尝试获取非对象的属性”
<?php
$html = file_get_contents('http://www.google.com/#q=ps3&tbm=shop'); //get the html returned from the following url
$glist = array();
$gdoc = new DOMDocument();
libxml_use_internal_errors(TRUE); //disable libxml errors
if(!empty($html)){ //if any html is actually returned
$gdoc->loadHTML($html);
libxml_clear_errors(); //remove errors for yucky html
$gxpath = new DOMXPath($gdoc);
$name = $gxpath->query('b')->item(0)->nodeValue;
}
echo "<pre>";
print_r($glist);
echo "</pre>";
?>
你能帮忙的话,我会很高兴!
没有更多信息,很难确定其来源。
奇怪的是,它来自以下行:
$name = $gxpath->query('b')->item(0)->nodeValue;
可能是查询,项目或nodeValue不存在。尝试打印$ gxpath的内容,然后打印$ gxpath-> query('b')等,这样您就可以弄清楚发生了什么。
附带说明,您在打印$ glist时实际上不执行任何操作,除了创建数组。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句