Skip to content

Commit b18eb9e

Browse files
committed
Add cocktailexplorer scraper
1 parent a465d40 commit b18eb9e

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

app/Scraper/Manager.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ final class Manager
3030
\Kami\Cocktail\Scraper\Sites\MakeMeACocktail::class,
3131
\Kami\Cocktail\Scraper\Sites\KindredCocktails::class,
3232
\Kami\Cocktail\Scraper\Sites\CraftedPour::class,
33+
\Kami\Cocktail\Scraper\Sites\CocktailExplorer::class,
3334
];
3435

3536
public function __construct(private readonly string $url)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Kami\Cocktail\Scraper\Sites;
6+
7+
use Kami\RecipeUtils\AmountValue;
8+
use Kami\RecipeUtils\RecipeIngredient;
9+
use Symfony\Component\DomCrawler\Crawler;
10+
11+
class CocktailExplorer extends DefaultScraper
12+
{
13+
public static function getSupportedUrls(): array
14+
{
15+
return [
16+
'https://www.cocktailexplorer.co',
17+
];
18+
}
19+
20+
public function ingredients(): array
21+
{
22+
$result = $this->crawler->filter('.video__recipe__ingredients li')->each(function (Crawler $node): RecipeIngredient {
23+
$amount = $node->filter('.video__recipe__ingredient__quantity')->attr('data-ingredient-amount');
24+
$unit = $node->filter('.video__recipe__ingredient__quantity')->attr('data-ingredient-unit');
25+
$ingredient = $node->filter('strong')->text();
26+
27+
return new RecipeIngredient(
28+
name: $ingredient,
29+
amount: AmountValue::fromString($amount),
30+
units: $unit,
31+
source: $node->text(),
32+
);
33+
});
34+
35+
return $result;
36+
}
37+
}

0 commit comments

Comments
 (0)