You can use node traversing
https://symfony.com/doc/current/components/dom_crawler.html#node-traversing
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi, I'm using Goutte to scrap websites containing prices. I want to know how can I scrap the title of the product and the price in one scrap?
This is the div:
<div class="product-details">
<h4 class="product-name">Name</h4>
<a class="price-button">Price</a>
</div>
What I have been doing to scrap a single thing from this div is this:
$crawler = Goutte::request('GET', 'https://elko.is/snjallheimilid/snjallperur');
$crawler->filter('div > .product-details > .price-button')->each(function ($node) {
dump($node->text());
});
return view('welcome');
I was able to figure this out.
$crawler = Goutte::request('GET', 'https://elko.is/snjallheimilid/snjallperur');
$crawler->filter('.product-details')->each(function ($node) {
$object = json_encode($node->children()->each(function ($product) {
return $product->text();
}));
dump(json_decode($object));
});
return view('welcome');
Please or to participate in this conversation.