Files
karudhaas/app/Services/ThiladhunService.php
2021-06-10 00:40:01 +05:00

34 lines
1022 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
{
//Return only the rss that contains "news" keyboard in its url
$response = Http::get("https://thiladhun.com/feed")->body();
$data = json_decode(json_encode(simplexml_load_string($response)), true);
$articles = $data["channel"]["item"];
$articlesitems = [];
//Looping through the articles and scraping and while scraping it creates a new instance of the scraper.
foreach ($articles as $article) {
//Remove query strings
$articlesitems[] = (new ThiladhunScraper)->extract(Str::before($article["link"], '?'), $article["pubDate"]);
}
return $articlesitems;
}
}