From cbe2c598989882f422d99064850d7cdc0ba64070 Mon Sep 17 00:00:00 2001 From: Mohamed Jinas Date: Mon, 10 Aug 2020 06:17:41 +0500 Subject: [PATCH] Update MihaaruService.php --- app/Services/MihaaruService.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/app/Services/MihaaruService.php b/app/Services/MihaaruService.php index f7315f0..64c084b 100644 --- a/app/Services/MihaaruService.php +++ b/app/Services/MihaaruService.php @@ -3,27 +3,30 @@ namespace App\Services; use App\Services\Scrapers\MihaaruScraper; +use Illuminate\Support\Str; class MihaaruService extends Client -{ +{ /** * Scrap all the rss articles from mihaaru * * @return array */ - public function scrape() : array + public function scrape(): array { - - $articles = $this->get("https://mihaaru.com/rss")["channel"]["item"]; + //Return only the rss that contains "news" keyboard in its url + $articles = collect($this->get("https://mihaaru.com/rss")["channel"]["item"]) + ->filter(function ($item, $key) { + return Str::of($item["link"])->contains(['news']); + }); $articlesitems = []; - $scraper = new MihaaruScraper(); - + //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']; $guid = $article['guid']; - $articlesitems[] = $scraper->extract($link, $date, $guid); + $articlesitems[] = (new MihaaruScraper)->extract($link, $date, $guid); } return $articlesitems;