0
這裏我試圖從網頁獲取地址和電話號碼。這裏是沒有給出任何錯誤,但也沒有給出任何結果的代碼。使用html dom和類名颳去數據
有什麼問題嗎?
我想從頁面獲取address
,1個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);
感謝花花公子,但它給''streetAddressaddressLocalityaddressRegionpostalCode而不是值。看看有什麼問題 – user123
使用'$ address。= $ comment-> plaintext;'或'$ address。= $ comment-> innertext;'這將返回文本。 – Manibharathi
@Manirbharathi:謝謝,它給了地址與明文。我使用了純文本和innertext圖像和手機,但這兩個都沒有打印 – user123