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

32 lines
942 B
PHP

<?php
namespace App\Services;
use App\Services\Feeds\ThiladhunFeed;
use App\Services\Scrapers\ThiladhunScraper;
use Illuminate\Support\Facades\Http;
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) {
$articlesitems[] = (new ThiladhunScraper)->extract($article["link"], $articles["pubDate"]);
}
return $articlesitems;
}
}