✨ Ajoute le Parser Lannion Immo
This commit is contained in:
parent
2dcdefe8e5
commit
56866735b0
64
app/Parser/LannionImmo.php
Normal file
64
app/Parser/LannionImmo.php
Normal 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;
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use App\Parser\LannionImmo;
|
||||
use App\Parser\LBC;
|
||||
use App\Parser\OuestFrance;
|
||||
use App\Parser\Pap;
|
||||
@ -11,5 +12,6 @@ return [
|
||||
'seloger.com' => SeLoger::class,
|
||||
'pap.fr' => Pap::class,
|
||||
'ouestfrance-immo.com' => OuestFrance::class,
|
||||
'lannion.immo' => LannionImmo::class
|
||||
],
|
||||
];
|
||||
|
Loading…
Reference in New Issue
Block a user