php简单html dom解析器不';我什么也不退

php简单html dom解析器不';我什么也不退,php,html-parsing,simpledom,Php,Html Parsing,Simpledom,为什么我的脚本不返回id为“pp”的div 这让我上路了。谢谢你的帮助 <?php include_once 'lib/simple_html_dom.php'; $url = "http://maps.google.com/maps/place?cid=6703996311168776503&q=hills+garage&hl=en&view=feature&mcsrc=google_reviews&num=20&start=0&

为什么我的脚本不返回id为“pp”的div


这让我上路了。谢谢你的帮助

<?php

include_once 'lib/simple_html_dom.php';

$url = "http://maps.google.com/maps/place?cid=6703996311168776503&q=hills+garage&hl=en&view=feature&mcsrc=google_reviews&num=20&start=0&ved=0CFUQtQU&sa=X&ei=sCq_Tr3mJZToygTOmuCGCg";

$html = file_get_html($url);

$ret =  $html->find('div[id=pp-reviews]');

foreach($ret as $story)
    echo $story;

?>

库始终返回一个数组,因为可能有多个项与选择器匹配

如果只需要一个页面,则应检查以确保所分析的页面的行为符合预期

建议的解决办法:

<?php

include_once 'lib/simple_html_dom.php';

$url = "http://maps.google.com/maps/place?cid=6703996311168776503&q=hills+garage&hl=en&view=feature&mcsrc=google_reviews&num=20&start=0&ved=0CFUQtQU&sa=X&ei=sCq_Tr3mJZToygTOmuCGCg";

$html = file_get_html($url);

$ret =  $html->find('div[id=pp-reviews]');
if(count($ret)==1){
echo $ret[0]->save();
}
else{
echo "Something went wrong";
}

什么是
回送$ret
yield?通常在CSS中,选择器是
div[id=“pp-featured”]
,不确定您使用的这个类是否对此严格要求。但是,如果您要查找ID,为什么不直接使用
div#pp-featured
?这个类不支持吗?@animuson我只是在使用手册中的示例。你说的单词数组是什么意思?它不会输出HTML吗?不会。只有那个词。获取此错误:致命错误:对中的非对象调用成员函数find()。。。
<?php

include_once 'lib/simple_html_dom.php';

$url = "http://maps.google.com/maps/place?cid=6703996311168776503&q=hills+garage&hl=en&view=feature&mcsrc=google_reviews&num=20&start=0&ved=0CFUQtQU&sa=X&ei=sCq_Tr3mJZToygTOmuCGCg";

$html = file_get_html($url);

$ret =  $html->find('div[id=pp-reviews]');
if(count($ret)==1){
echo $ret[0]->save();
}
else{
echo "Something went wrong";
}