Files
karudhaas/app/Services/Scrapers/ZaviyaniScraper.php

56 lines
1.6 KiB
PHP

<?php
namespace App\Services\Scrapers;
use Goutte\Client;
use Illuminate\Support\Carbon;
class ZaviyaniScraper
{
protected $client;
protected $title;
protected $content;
protected $topics = [];
protected $author = "unknown";
public function __construct()
{
$this->client = new Client;
}
public function extract($url, $date)
{
$crawler = $this->client->request('GET', $url);
$crawler->filter('.content-inner p')->each(function ($node) {
$this->content[] = $node->text();
});
if ($crawler->filter('div[class*="jeg_meta_author"] a')->count() == 1) {
$this->author = $crawler->filter('div[class*="jeg_meta_author"] a')->first()->text();
}
//Remove all the alphabets from string
//preg_replace("/[a-zA-Z]/", "",$string);
return [
'source' => 'Zaviyani',
'title' => $crawler->filter('h1')->first()->text(),
'og_title' => $crawler->filter('meta[property*="og:title"]')->first()->attr('content'),
'image' => $crawler->filter(".featured_image img")->first()->attr('data-src'),
'content' => $this->content,
'url' => $url,
'date' => Carbon::parse($date)->format("Y-m-d H:i:s"),
'guid' => str_replace("https://zaviyani.mv/?p=", "", $url),
'author' => $this->author,
'topics' => [
[
"name" => "ވަކި މަޢުލޫއެއް ނޭންގެ",
"slug" => "no-specific-topic"
]
]
];
}
}