Files
karudhaas/app/Services/Scrapers/MinoosScraper.php
2024-01-12 04:34:28 +05:00

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
];
}
}