From d5ffdd8699488f9eed347d2057ec972586accbc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment?= Date: Thu, 28 Jan 2021 17:11:51 +0100 Subject: [PATCH] :sparkles: Ajoute le parser Safti Fix #20 --- app/Parser/Safti.php | 67 ++++++++++++++++++++++++++++++++++++++++++++ config/parser.php | 4 ++- 2 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 app/Parser/Safti.php diff --git a/app/Parser/Safti.php b/app/Parser/Safti.php new file mode 100644 index 0000000..8e8aa11 --- /dev/null +++ b/app/Parser/Safti.php @@ -0,0 +1,67 @@ +client->get($this->url); + $body = $request->getBody()->getContents(); + $crawler = new Crawler($body); + $parsed_home = new ParsedHome(); + + $property_single = $crawler->filter('[data-testid="real-estate"]'); + + $number_formatter = new NumberFormatter('en', NumberFormatter::DECIMAL); + $currency_formatter = new NumberFormatter('en', NumberFormatter::CURRENCY); + $currency = 'EUR'; + + $parsed_home->title = $property_single->filter('h1')->text(); + $parsed_home->price = $currency_formatter->parseCurrency($property_single->filter('.property__price')->text(), $currency); + $parsed_home->city = $property_single->children()->children('div')->eq(1)->filter('p.h4')->text(); + $parsed_home->description = $crawler->filter('[data-testid="real-estate-annonce-single-description"]')->text(); + + $property__additionals = $crawler->filter('.property__additionals'); + $energies = $property__additionals->filter('.energetic-indicator'); + if ($energies->count() > 0) { + $parsed_home->energy = substr($energies->eq(0)->text(), 0, 1); + $parsed_home->ges = substr($energies->eq(1)->text(), 0, 1); + } + + $crawler + ->filter('.property__informations .mobile-extends > div .property__informations__element') + ->each(static function (Crawler $property____information, $i) use (&$parsed_home, $number_formatter) { + $name = trim($property____information->filter('i')->text()); + $value = trim($property____information->filter('b')->text()); + switch ($name) { + case 'Pièces :': + $parsed_home->rooms = (int)$value; + break; + case 'Surface habitable :': + $parsed_home->surface = $number_formatter->parse($value); + break; + case 'Terrain :': + $parsed_home->garden_surface = $number_formatter->parse($value); + break; + default: +// break; + } + }); + + $parsed_home->pictures = $crawler->filter('[data-testid="real-estate-mosaic-photo"]')->filter('img')->each(static function($img) { + return $img->attr('src'); + }); + + return $parsed_home; + } +} diff --git a/config/parser.php b/config/parser.php index 011bc2a..ebce0d8 100644 --- a/config/parser.php +++ b/config/parser.php @@ -6,6 +6,7 @@ use App\Parser\LBC; use App\Parser\Orpi; use App\Parser\OuestFrance; use App\Parser\Pap; +use App\Parser\Safti; use App\Parser\SeLoger; return [ @@ -16,6 +17,7 @@ return [ 'ouestfrance-immo.com' => OuestFrance::class, 'lannion.immo' => LannionImmo::class, 'immobilier.notaires.fr'=> ImmobilierNotaires::class, - 'orpi.com' => Orpi::class + 'orpi.com' => Orpi::class, + 'safti.fr' => Safti::class, ], ]; -- 2.30.2