✨ Ajoute le parser Ouest-France #13
@ -2,9 +2,7 @@
|
|||||||
|
|
||||||
namespace App;
|
namespace App;
|
||||||
|
|
||||||
use App\Parser\LBC;
|
use GuzzleHttp\Client;
|
||||||
use App\Parser\Pap;
|
|
||||||
use App\Parser\SeLoger;
|
|
||||||
use Illuminate\Support\Facades\Config;
|
use Illuminate\Support\Facades\Config;
|
||||||
|
|
||||||
abstract class Parser
|
abstract class Parser
|
||||||
@ -15,7 +13,7 @@ abstract class Parser
|
|||||||
protected function __construct($url)
|
protected function __construct($url)
|
||||||
{
|
{
|
||||||
$this->url = $url;
|
$this->url = $url;
|
||||||
$this->client = new \GuzzleHttp\Client([
|
$this->client = new Client([
|
||||||
'timeout' => 60,
|
'timeout' => 60,
|
||||||
'verify' => false,
|
'verify' => false,
|
||||||
'headers' => [
|
'headers' => [
|
||||||
|
43
app/Parser/OuestFrance.php
Normal file
43
app/Parser/OuestFrance.php
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<?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 = ?
|
||||||
|
$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;
|
||||||
|
}
|
||||||
|
}
|
@ -1,13 +1,15 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Parser\LBC;
|
use App\Parser\LBC;
|
||||||
|
use App\Parser\OuestFrance;
|
||||||
use App\Parser\Pap;
|
use App\Parser\Pap;
|
||||||
use App\Parser\SeLoger;
|
use App\Parser\SeLoger;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'parsers' => [
|
'parsers' => [
|
||||||
'leboncoin.fr' => LBC::class,
|
'leboncoin.fr' => LBC::class,
|
||||||
'seloger.com' => SeLoger::class,
|
'seloger.com' => SeLoger::class,
|
||||||
'pap.fr' => Pap::class,
|
'pap.fr' => Pap::class,
|
||||||
|
'ouestfrance-immo.com' => OuestFrance::class,
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
Loading…
Reference in New Issue
Block a user