我正在使用ganon dom解析器进行HTML解析,并试图从DIV块中获取内容,但由于某种原因,返回的对象无法工作,以下是我的代码,我正在使用:
<?php
set_time_limit(0);
#Include the dom parser lib.
require_once('ganon.php');
$html = file_get_dom('http://jlc.watchprosite.com/?show=forumpost&fi=2&pi=1818820&ti=279373&msid=&s=');
print_r($html("div[id='sidebar']")->childCount());
?>这给了我们
Fatal error: Call to a member function childCount() on a non-object in D:\xampp\htdocs\govberg\test.php on line 7当我执行print_r($html)时,它打印的是一个大对象。
任何人都能指出哪里出了问题..
发布于 2013-12-12 21:13:23
像这样试一下,
if ($html("div[id='sidebar']",0)){ // or use # like if ($html("div#sidebar",0)){
echo 'Total children are '.$html("div[id='sidebar']",0)->childCount();
}https://stackoverflow.com/questions/18123933
复制相似问题