0

スクリプトが「pp-featured」の ID を持つ div を返さないのはなぜですか?

<?php
# create and load the HTML  
include('lib/simple_html_dom.php');  
$html = new simple_html_dom();  
$html->load("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");  

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

# output it!  
echo $ret->save();
?>
4

2 に答える 2

0

複数の項目がセレクターに一致する可能性があるため、ライブラリーは常に配列を返します。

1 つだけが予想される場合は、分析が期待どおりに動作していることを確認する必要があります。

推奨される解決策:

<?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";
}
于 2013-06-11T05:37:27.457 に答える
0

これは私の道に私を取得します。ご協力いただきありがとうございます。

<?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;

?>
于 2011-11-21T06:10:25.097 に答える