I'm using Goutte (a web scraper) for the first time. I'm following a tutorial that my teacher made and I'm following it with much attention. However, when I'm trying to dump and die the scraped data, it always returns an empty array and I can't see where my fault is. Can anyone see what I'm doing wrong?
My code:
private function scrapeMazoet($url)
{
$client = new Client();
$crawler = $client->request('GET', $url);
$categories = $crawler->filter('.main-menu-container .menu #menu-item-454 .sub-menu #menu-item-2483 .ul-multiple-col #menu-item-3827 a')
->each(function($node) {
$title = $node->text();
dump($title);
});
dd($categories);
}
I figured it out by working step by step instead of trying to give the full path in one take. Some inputs where not recognisable by Goutte so had to grab the info in a different way. I'll show the bad and good method as an example:
The wrong way:
$categories = $crawler->filter('.main-menu-container .menu #menu-item-454 .sub-menu #menu-item-2483 .ul-multiple-col #menu-item-3827 a')
The correct way:
$categories = $crawler->filter('#menu-item-2483 ul li a')
I think you should make it yourself easy and start with the most closest id to start and work your way through.