MyHomeCollection/app/Parser/OuestFrance.php

46 lines
1.4 KiB
PHP
Raw Normal View History

<?php
namespace App\Parser;
use App\ParsedHome;
use App\Parser;
use Symfony\Component\DomCrawler\Crawler;
class OuestFrance extends Parser
{
/**
* @inheritDoc
*/
public function parse(): ParsedHome
{
/*
public $map
*/
$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('#strongPrix')->text();
$parsedHome->description = $crawler->filter('#blockonDescriptif')->text();
$details = $crawler->filter('#blocCaractAnn > ul > li');
$parsedHome->surface = (int)$details->eq(2)->filter('strong')->text();
$parsedHome->garden_surface = (int)$details->eq(3)->filter('strong')->text();
$parsedHome->rooms = (int)$details->eq(4)->filter('strong')->text();
$parsedHome->energy = $crawler->filter('#dpeCateg > strong')->text();
// $parsedHome->city = ?
// $parsedHome->map = ?
2020-07-27 16:17:24 +02:00
$parsedHome->pictures = $crawler
->filter('#slider > noscript > .slides > li')
->each(static function (Crawler $node, $i) {
if ($node->children('img')) {
return $node->children('img')->attr('src');
}
2020-07-27 16:17:24 +02:00
return null;
});
return $parsedHome;
}
}