【发布时间】:2014-04-29 07:46:13
【问题描述】:
有类似的线程可用。我看着他们并试图得到。在这里我可以得到地址值,但phone 号码和image url 没有来。
这里哪里出错了?
function getData($url){
$containers1 = $html->find('div.mapbox div.mapbox-text strong.street-address address');
foreach($containers1 as $container)
{
$comments = $container->find('span');
$item = new stdClass();
foreach($comments as $comment)
{
$address.= $comment->plaintext; //append the content of each span
}
echo $address; // this gives correct result
}
$containers2 = $html->find('div.mapbox div.mapbox-text span.biz-phone');
$phone = $containers2->innertext;
echo "<br/>".$phone."<br/>"; // no result
$Imgcontainers = $html->find('div.js-photo photo photo-1 div.showcase-photo-box img');
echo $Imgcontainers->getAttribute('src'); // Fatal error: Call to a member function getAttribute() on a non-object
}
}
$url = 'http://www.yelp.com/biz/locanda-san-francisco?start=40';
$root = getData($url);
更新
我添加了这个:
$Imgcontainers = $html->find('div.photo-1 img');
foreach($Imgcontainers as $cont){
$img[] = $cont->getAttribute('src');
}
echo $img[0];
两次相同的网址?为什么我们只回显第 0 个数组值?
【问题讨论】:
-
你在使用简单的 HTML DOM 解析器吗?
-
只需使用一个独特的类来读取图像标签 $Imgcontainers = $html->find('div.photo-1 img');