49 lines
1.3 KiB
PHP
49 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Scrapers;
|
|
|
|
use Goutte\Client;
|
|
use Symfony\Component\DomCrawler\Crawler;
|
|
use Illuminate\Support\Carbon;
|
|
|
|
class MinoosScraper
|
|
{
|
|
protected $client;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->client = new Client();
|
|
}
|
|
|
|
public function extract($url, $date = null, $highlights = null)
|
|
{
|
|
$crawler = $this->client->request('GET', $url);
|
|
|
|
$title = $crawler->filter('h1')->first()->text();
|
|
$content = $crawler->filter('.doc-text')->each(function (Crawler $node) {
|
|
return $node->text();
|
|
});
|
|
$image = $crawler->filter('meta[property="og:image"]')->attr('content');
|
|
|
|
$topics = $crawler->filter('a[href^="/tags/"]')->each(function (Crawler $node) {
|
|
return [
|
|
'name' => $node->text(),
|
|
'slug' => str_replace("/tags/", "", $node->attr('href'))
|
|
];
|
|
});
|
|
|
|
return [
|
|
'source' => 'minoos',
|
|
'title' => $title,
|
|
'guid' => basename($url),
|
|
'content' => $content,
|
|
'author' => 'unknown',
|
|
'image' => $image,
|
|
'highlights' => $highlights,
|
|
'url' => $url,
|
|
'date' => Carbon::parse($date)->format("Y-m-d H:i:s"),
|
|
'topics' => $topics
|
|
];
|
|
}
|
|
}
|