试图获取非对象的属性简单的HTML DOM解析器

dha*_*bro 3 php simple-html-dom

我试图<div class="clearfix" id="searchResultsDiv">从我的代码中的链接获取内容.无论我尝试什么,它都会显示如下通知

注意:尝试在第20行的E:\ xampp\htdocs\homeshop\index.php中获取非对象的属性

$link="http://www.homeshop18.com/samsung/categoryid:3027/search:samsung/inStock:true/sort:Popularity/?it_category=MN&it_action=MA-MMAA01&it_label=MN-MMAA01-140906000003-PD-MA-OT-OT-SR_Samsung-0_0-0-MNU101-MA-140730-OT-OT-SR&it_value=0";
$productPage=file_get_html($link);
$wholeContent=$productPage->find('div[id=searchResultsDiv]');
echo $wholeContent->plaintext; //line 20
Run Code Online (Sandbox Code Playgroud)

有一个这个id的元素,但我仍然无法做到这一点.哪里错了?

Bar*_*mar 10

find返回一个匹配元素数组,即使只有一个匹配.您需要将其编入索引以获取元素.

if ($wholeContent) {
    echo $wholeContent[0]->plaintext;
}
Run Code Online (Sandbox Code Playgroud)