Files
karudhaas/app/Services/AvasService.php
2020-10-06 01:11:23 +05:00

29 lines
809 B
PHP

<?php
namespace App\Services;
use App\Services\Feeds\AvasFeed;
use App\Services\Scrapers\AvasScraper;
class AvasService
{
/**
* Scrap all the rss articles from Sun
*
* @return array
*/
public function scrape(): array
{
//Return only the rss that contains "news" keyboard in its url
$articles = (new AvasFeed)->get();
$articlesitems = [];
//Looping through the articles and scraping and while scraping it creates a new instance of the scraper.
foreach ($articles as $article) {
$scraped_article = (new AvasScraper)->extract($article["link"], $article["date"]);
if (!is_null($scraped_article)) {
$articlesitems[] = $scraped_article;
}
}
return $articlesitems;
}
}