Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

nday's avatar
Level 1

Parsing images with DomCrawler

Hi all! i'm stuck with a problem with DomCrawler. When I try to do next code:

for($i=0; $i<5; $i++) {
$html = file_get_contents('https://auto.ria.com/legkovie/?page=' . $i);
$crawler = new Crawler($html);

$crawler = $crawler->filterXPath('//div[@class="content-bar"]');

    foreach ($crawler as $domElement) {
        $crawlerImage = $crawler->filter('img')->attr('src');
        var_dump($crawlerImage);
//        var_dump($domElement->nodeValue);
        echo "<br><br><br>";
    }
}

I'm getting list of same links of first image on the page instead of correct ones. How could I fix that?

0 likes
0 replies

Please or to participate in this conversation.