Files
karudhaas/app/Services/JazeeraService.php
2021-02-05 03:27:37 +05:00

31 lines
893 B
PHP

<?php
namespace App\Services;
use App\Services\Scrapers\JazeeraScraper;
use Illuminate\Support\Facades\Http;
class JazeeraService extends Client
{
/**
* Scrap all the rss articles from Thiladhun
*
* @return array
*/
public function scrape(): array
{
//Return only the rss that contains "news" keyboard in its url
$articles = json_decode(json_encode(simplexml_load_string(Http::get("https://jazeera.mv/feed/")->body())),true)["channel"]["item"];
$articlesitems = [];
//Looping through the articles and scraping and while scraping it creates a new instance of the scraper.
foreach ($articles as $article) {
$link = $article['link'];
$date = $article['pubDate'];
$articlesitems[] = (new JazeeraScraper)->extract($link,$date);
}
return $articlesitems;
}
}