48 lines
1.7 KiB
PHP
48 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Parser;
|
|
|
|
use App\ParsedHome;
|
|
use App\Parser;
|
|
use Symfony\Component\DomCrawler\Crawler;
|
|
|
|
class OuestFrance 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();
|
|
$details = $crawler->filter('#blocCaractAnn > ul > li');
|
|
$price = $crawler->filter('#strongPrix');
|
|
if (!$price instanceof Crawler) {
|
|
$price = $details->eq(0)->filter('strong')->text();
|
|
}
|
|
$parsedHome->price = (int)str_replace(' ', '', $price->text());
|
|
$parsedHome->description = $crawler->filter('#blockonDescriptif')->text();
|
|
$parsedHome->surface = (int)str_replace(' ', '', $details->eq(2)->filter('strong')->text());
|
|
$parsedHome->garden_surface = (int)str_replace(' ', '', $details->eq(3)->filter('strong')->text());
|
|
$parsedHome->rooms = (int)str_replace(' ', '', $details->eq(4)->filter('strong')->text());
|
|
$dpeCateg = $crawler->filter('#dpeCateg > strong');
|
|
$parsedHome->energy = $dpeCateg->count() === 1 ? $dpeCateg->text() : '';
|
|
// $parsedHome->city = ?
|
|
// $parsedHome->map = ?
|
|
$parsedHome->pictures = $crawler
|
|
->filter('#slider > noscript > .slides > li')
|
|
->each(static function (Crawler $node, $i) {
|
|
if ($node->children('img')) {
|
|
return $node->children('img')->attr('src');
|
|
}
|
|
|
|
return null;
|
|
});
|
|
|
|
return $parsedHome;
|
|
}
|
|
}
|