Ajoute le parser Safti #21

Merged
Shikiryu merged 1 commits from feature/safti/20 into main 2021-01-28 17:13:54 +01:00
2 changed files with 70 additions and 1 deletions

67
app/Parser/Safti.php Normal file
View File

@ -0,0 +1,67 @@
<?php
namespace App\Parser;
use App\ParsedHome;
use App\Parser;
use NumberFormatter;
use Symfony\Component\DomCrawler\Crawler;
class Safti extends Parser
{
/**
* @inheritDoc
*/
public function parse(): ParsedHome
{
$request = $this->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;
}
}

View File

@ -6,6 +6,7 @@ use App\Parser\LBC;
use App\Parser\Orpi; use App\Parser\Orpi;
use App\Parser\OuestFrance; use App\Parser\OuestFrance;
use App\Parser\Pap; use App\Parser\Pap;
use App\Parser\Safti;
use App\Parser\SeLoger; use App\Parser\SeLoger;
return [ return [
@ -16,6 +17,7 @@ return [
'ouestfrance-immo.com' => OuestFrance::class, 'ouestfrance-immo.com' => OuestFrance::class,
'lannion.immo' => LannionImmo::class, 'lannion.immo' => LannionImmo::class,
'immobilier.notaires.fr'=> ImmobilierNotaires::class, 'immobilier.notaires.fr'=> ImmobilierNotaires::class,
'orpi.com' => Orpi::class 'orpi.com' => Orpi::class,
'safti.fr' => Safti::class,
], ],
]; ];