From 0902d9da4303f34cc802fa786c7fa74f604afe7c Mon Sep 17 00:00:00 2001 From: Mohamed Jinas Date: Mon, 24 Aug 2020 14:51:49 +0500 Subject: [PATCH] switched the press to a virtual feed --- app/Services/Feeds/ThePressFeed.php | 37 +++++++++++++++++++++++++++++ app/Services/ThePressService.php | 3 ++- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 app/Services/Feeds/ThePressFeed.php diff --git a/app/Services/Feeds/ThePressFeed.php b/app/Services/Feeds/ThePressFeed.php new file mode 100644 index 0000000..2d73fdd --- /dev/null +++ b/app/Services/Feeds/ThePressFeed.php @@ -0,0 +1,37 @@ +client = new Client(); + } + /** + * Get all the latest news + * + * @return array + */ + public function get() : array + { + + $crawler = $this->client->request('GET', "https://thepress.mv/"); + + $feeds = []; + + $crawler->filter('div[class*="col-lg-3 col-lg-cm-5 col-md-6 col-6"] a')->each(function($node) use (&$feeds){ + $feeds[] = [ + "title" => $node->text(), + "link" => $node->attr('href') + ]; + }); + + return $feeds; + + + } +} \ No newline at end of file diff --git a/app/Services/ThePressService.php b/app/Services/ThePressService.php index ac3016b..c8ace51 100644 --- a/app/Services/ThePressService.php +++ b/app/Services/ThePressService.php @@ -3,6 +3,7 @@ namespace App\Services; use App\Services\Scrapers\ThePressScraper; +use App\Services\Feeds\ThePressFeed; use Illuminate\Support\Str; class ThePressService extends Client @@ -15,7 +16,7 @@ class ThePressService extends Client public function scrape(): array { //Return only the rss that contains "news" keyboard in its url - $articles = $this->get("https://thepress.mv/rss")["channel"]["item"]; + $articles = (new ThePressFeed)->get(); $articlesitems = [];