我在这里试图从网页上获取地址和电话号码。这是代码,它不会给出任何错误但也不会给出任何结果。
有什么不对吗?
我正在尝试从页面中获取address
,一个image
和phone
。
这是代码:
include_once('simple_html_dom.php');
function getData($url)
{
print("$url\n");
$root = new stdClass();
$items = array();
$html = file_get_html($url);
if($html) {
$containers = $html->find('div.mapbox div.mapbox-text strong.street-address address.address');
foreach($containers as $container) {
$comments = $container->find('address.address span');
$item = new stdClass();
foreach($comments as $comment) {
$address.= $comment->itemprop; //append the content of each span
}
echo $address;
$getphone = $container->find('span.biz-phone');
$phone = $getphone->itempro;
}
$Imgcontainers = $html->find('div.js-photo photo photo-1 div.showcase-photo-box img.a la beverly sills');
echo $Imgcontainers->img;
}
}
$url = 'http://www.yelp.com/biz/locanda-san-francisco?start='.$i.'';
$root = getData($url);
答案 0 :(得分:1)
在<address>
标记中没有address
类,因此$containers
返回空。在if
条件
$containers = $html->find('div.mapbox div.mapbox-text strong.street-address address');
foreach($containers as $container) {
$comments = $container->find('span');
$item = new stdClass();
foreach($comments as $comment) {
$address.= $comment->itemprop; //append the content of each span
}
echo $address;
$getphone = $container->find('span.biz-phone');
$phone = $getphone->itempro;
}
$Imgcontainers = $html->find('div.js-photo photo photo-1 div.showcase-photo-box img.a la beverly sills');
echo $Imgcontainers->img;