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

hjortur17's avatar

Use Goutte to scrap multiple data from single div

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');
0 likes
5 replies
hjortur17's avatar

@michaloravec - This is my first time working with this. Can you help me loop through this? I can't figure out how.

$crawler->filter('div > .product-details > .product-name')->first();
$crawler->filter('div > .product-details > .price-button')->last();
hjortur17's avatar
hjortur17
OP
Best Answer
Level 14

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.