Ajoute le Parser Lannion Immo

This commit is contained in:
Clement 2020-09-11 10:16:44 +02:00
parent 2dcdefe8e5
commit 56866735b0
2 changed files with 66 additions and 0 deletions

View File

@ -0,0 +1,64 @@
<?php
namespace App\Parser;
use App\ParsedHome;
use App\Parser;
use Symfony\Component\DomCrawler\Crawler;
class LannionImmo extends Parser
{
/**
* @inheritDoc
*/
public function parse(): ParsedHome
{
$request = $this->client->get($this->url);
$body = $request->getBody()->getContents();
$crawler = new Crawler($body);
$parsedHome = new ParsedHome();
$parsedHome->title = $crawler->filter('h1')->text();
$parsedHome->price = (int)$crawler->filter('[itemprop=price]')->attr('content');
$parsedHome->description = $crawler->filter('[itemprop=description]')->text();
$crawler
->filter('.tech_detail tr')
->each(static function (Crawler $detail, $i) use (&$parsedHome) {
foreach (range(1, 2) as $loop) {
$l = sprintf('.l%u', $loop);
$r = sprintf('.r%u', $loop);
$detail_name = $detail->filter($l);
if ($detail_name instanceof Crawler && $detail_name->count() > 0) {
switch ($detail_name->text()) {
case 'Surface':
$parsedHome->surface = (int)$detail->filter($r)->text();
break;
case 'Ville':
$parsedHome->city = $detail->filter($r)->text();
break;
case 'Pièces':
$parsedHome->rooms = (int)$detail->filter($r)->text();
break;
case 'Superficie du terrain':
$parsedHome->garden_surface = (int)$detail->filter($r)->text();
break;
default:
break;
}
}
}
});
$parsedHome->energy = substr($crawler->filter('.dpe-letter-active')->first()->text(), 0, 1);
$parsedHome->ges = substr($crawler->filter('.dpe-letter-active')->eq(1)->text(), 0, 1);
$parsedHome->pictures = $crawler
->filter('.rsImg')
->each(static function (Crawler $node, $i) {
if ($node->children('img')) {
return $node->children('img')->attr('src');
}
return null;
});
return $parsedHome;
}
}

View File

@ -1,5 +1,6 @@
<?php <?php
use App\Parser\LannionImmo;
use App\Parser\LBC; use App\Parser\LBC;
use App\Parser\OuestFrance; use App\Parser\OuestFrance;
use App\Parser\Pap; use App\Parser\Pap;
@ -11,5 +12,6 @@ return [
'seloger.com' => SeLoger::class, 'seloger.com' => SeLoger::class,
'pap.fr' => Pap::class, 'pap.fr' => Pap::class,
'ouestfrance-immo.com' => OuestFrance::class, 'ouestfrance-immo.com' => OuestFrance::class,
'lannion.immo' => LannionImmo::class
], ],
]; ];