Feshun Support
This commit is contained in:
26
app/Services/FeshunService.php
Normal file
26
app/Services/FeshunService.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Services\Scrapers\FeshunScraper;
|
||||
|
||||
class FeshunService extends Client
|
||||
{
|
||||
/**
|
||||
* Scrap all the rss articles from Thiladhun
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function scrape(): array
|
||||
{
|
||||
$articles = $this->get("https://feshun.mv/feed")["channel"]["item"];
|
||||
|
||||
$articlesitems = [];
|
||||
//Looping through the articles and scraping and while scraping it creates a new instance of the scraper.
|
||||
foreach ($articles as $article) {
|
||||
$articlesitems[] = (new FeshunScraper)->extract($article['link'], $article['pubDate']);
|
||||
}
|
||||
|
||||
return $articlesitems;
|
||||
}
|
||||
}
|
||||
75
app/Services/Scrapers/FeshunScraper.php
Normal file
75
app/Services/Scrapers/FeshunScraper.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Scrapers;
|
||||
|
||||
use Goutte\Client;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class FeshunScraper
|
||||
{
|
||||
protected $client;
|
||||
|
||||
protected $title;
|
||||
protected $content;
|
||||
protected $guid;
|
||||
protected $author;
|
||||
|
||||
/**
|
||||
* __construct.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->client = new Client();
|
||||
}
|
||||
|
||||
/**
|
||||
* extract.
|
||||
*
|
||||
* @param mixed $url
|
||||
* @param mixed $date
|
||||
* @param mixed $guid
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function extract($url, $date)
|
||||
{
|
||||
$this->guid = str_replace('https://feshun.mv/', '', $url);
|
||||
|
||||
$crawler = $this->client->request('GET', $url);
|
||||
|
||||
$crawler->filter('h3')->each(function ($node) {
|
||||
$this->title = $node->text();
|
||||
});
|
||||
|
||||
|
||||
$crawler->filter('.elementor-widget-container p')->each(function ($node) {
|
||||
$this->content[] = preg_replace("/[a-zA-Z]/", "", $node->text());;
|
||||
});
|
||||
|
||||
|
||||
$crawler->filter('li[itemprop*="author"] span')->each(function ($node) {
|
||||
$this->author = $node->text();
|
||||
});
|
||||
|
||||
|
||||
return [
|
||||
'source' => 'Feshun',
|
||||
'title' => $this->title,
|
||||
'og_title' => $crawler->filter('meta[property*="og:title"]')->first()->attr('content'),
|
||||
'image' => $crawler->filter('figure img')->first()->attr('src'),
|
||||
'content' => $this->content,
|
||||
'date' => Carbon::parse($date)->format("Y-m-d H:i:s"),
|
||||
'url' => $url,
|
||||
'author' => $this->author,
|
||||
'guid' => $this->guid,
|
||||
'topics' => [
|
||||
[
|
||||
"name" => "ވަކި މަޢުލޫއެއް ނޭންގެ",
|
||||
"slug" => "no-specific-topic"
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user