Reputation: 5407
Here I am trying to get address and phone number from the web page. Here is the code which does not give any error but also not give any result.
Is there something wrong?
I am trying to get address
, one image
and phone
from the page.
Here is code:
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);
Upvotes: 0
Views: 585
Reputation: 945
In <address>
tag doesn't have address
class so $containers
returns empty. Use below code in your if
condition
$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;
Upvotes: 1