dimanche 21 octobre 2018

Scraping data div after div with php DOMparser

I'm trying to scrape url div after div. But grabing just two url. It's not going after two...

libxml_use_internal_errors(true);
$url = 'http://www.sumitomo-rd-mansion.jp/kansai/';

$parser = getSiteContent($url);
$allDivs = [];
$allDivs = $parser->getElementsByTagName('div');
foreach ($allDivs as $div) {
    if ($div->getAttribute('class') == 'areaBox clearfix') {
        if ($div != null) {
            $links = $div->getElementsByTagName('a');
            if ($links->length > 0) {
                $a = $links->item(0);
                $linkRef = $a->getAttribute('href');
                $link [] = $linkRef;
            }
        }
    }
}

var_dump($link);

  [0]=>
  string(65) "http://www.sumitomo-rd-mansion.jp/kansai/higashi_umeda/index.html"
  [1]=>
  string(60) "http://www.sumitomo-rd-mansion.jp/kansai/osaka745/index.html"
}

it's giving me just these two and not going to next areaBox clearfix so what it is the problem here? Any idea?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire