From 32888bd5b26fb7fe506384fa792660c67b21bd87 Mon Sep 17 00:00:00 2001 From: Mohamed Jinas Date: Tue, 6 Oct 2020 01:11:23 +0500 Subject: [PATCH] Avas fix --- app/Console/Kernel.php | 5 ++--- app/Services/AvasService.php | 5 ++++- app/Services/Scrapers/AvasScraper.php | 5 +++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 580cf00..d8e01d6 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -26,9 +26,8 @@ class Kernel extends ConsoleKernel protected function schedule(Schedule $schedule) { $schedule->command('scrape:mihaaru')->everyFiveMinutes() - ->pingOnSuccess(env('APP_URL') . "/api/ping/mihaaru") - ->runInBackground(); - + ->runInBackground() + ->pingOnSuccess(env('APP_URL') . "/api/ping/mihaaru"); $schedule->command('scrape:sun')->everyFiveMinutes() ->runInBackground() diff --git a/app/Services/AvasService.php b/app/Services/AvasService.php index ac7d431..75c195e 100644 --- a/app/Services/AvasService.php +++ b/app/Services/AvasService.php @@ -18,7 +18,10 @@ class AvasService $articlesitems = []; //Looping through the articles and scraping and while scraping it creates a new instance of the scraper. foreach ($articles as $article) { - $articlesitems[] = (new AvasScraper)->extract($article["link"], $article["date"]); + $scraped_article = (new AvasScraper)->extract($article["link"], $article["date"]); + if (!is_null($scraped_article)) { + $articlesitems[] = $scraped_article; + } } return $articlesitems; diff --git a/app/Services/Scrapers/AvasScraper.php b/app/Services/Scrapers/AvasScraper.php index f984c86..c952d66 100644 --- a/app/Services/Scrapers/AvasScraper.php +++ b/app/Services/Scrapers/AvasScraper.php @@ -30,6 +30,11 @@ class AvasScraper $this->image = $crawler->filter('figure img')->first()->attr('src'); } + if($crawler->filter('.post_content p')->count() == 0) + { + return; + } + $crawler->filter('.post_content p')->each(function ($node) { $this->content[] = preg_replace("/[a-zA-Z]/","",$node->text()); });