From 83132bc45c96d1a0e1a283c58d8eef9757965a0c Mon Sep 17 00:00:00 2001 From: Mohamed Jinas Date: Fri, 2 Oct 2020 16:22:34 +0500 Subject: [PATCH] Update DhenScraper.php --- app/Services/Scrapers/DhenScraper.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/Services/Scrapers/DhenScraper.php b/app/Services/Scrapers/DhenScraper.php index 10d558a..bff30e5 100644 --- a/app/Services/Scrapers/DhenScraper.php +++ b/app/Services/Scrapers/DhenScraper.php @@ -23,9 +23,10 @@ class DhenScraper $title = $crawler->filter('h1')->first()->text(); - - - $image = $crawler->filter('article .article-visual img')->first()->attr('src'); + if($crawler->filter('article .article-visual img')->count() == 1) + { + $image = $crawler->filter('article .article-visual img')->first()->attr('src'); + } $crawler->filter('article .article-entry p')->each(function ($node) { $this->content[] = preg_replace("/[a-zA-Z]/","",$node->text()); @@ -44,7 +45,7 @@ class DhenScraper 'source' => 'Dhen', 'title' => $title, 'og_title' => $crawler->filter('meta[property*="og:title"]')->first()->attr('content'), - 'image' => $image, + 'image' => $image ?? "images/noimg.jpg", 'content' => $this->content, 'url' => $url, 'date' => Carbon::parse(str_replace("- ", "", $crawler->filter('.story-item--meta time')->first()->text()))->format("Y-m-d H:i:s"),