Files
karudhaas/app/Services/ThiladhunService.php
Mohamed jinas fbaa43748f WIP
2024-01-07 21:54:36 +05:00

36 lines
948 B
PHP

<?php
namespace App\Services;
use App\Services\Feeds\ThiladhunFeed;
use App\Services\Scrapers\ThiladhunScraper;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Str;
class ThiladhunService extends Client
{
/**
* Scrap all the rss articles from Thiladhun
*
* @return array
*/
public function scrape(): array
{
$articles = (new ThiladhunFeed)->get();
$articlesitems = [];
// Looping through the articles and scraping and while scraping it creates a new instance of the scraper.
foreach ($articles as $article) {
// Scrape the article
$scrapedArticle = (new ThiladhunScraper)->extract($article["link"]);
// Check if the scraped article is not null
if ($scrapedArticle !== null && !empty($scrapedArticle)) {
$articlesitems[] = $scrapedArticle;
}
}
return $articlesitems;
}
}