From 3c6c2a0b2149b59e774cf409f0909ad616a54221 Mon Sep 17 00:00:00 2001 From: Mohamed Jinas Date: Thu, 1 Oct 2020 01:56:48 +0500 Subject: [PATCH] Pattern fix --- app/Services/Scrapers/DhuvasScraper.php | 29 ++++++++++++++++++------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/app/Services/Scrapers/DhuvasScraper.php b/app/Services/Scrapers/DhuvasScraper.php index 2428a76..1a0d74a 100644 --- a/app/Services/Scrapers/DhuvasScraper.php +++ b/app/Services/Scrapers/DhuvasScraper.php @@ -27,21 +27,34 @@ class DhuvasScraper $this->title = $node->text(); }); - $crawler->filter('.elementor-widget-container > p')->each(function ($node) { - $this->content[] = preg_replace("/[a-zA-Z]/","",$node->text()); - }); + // Checking for two types of article patterns + if ($crawler->filter('.elementor-widget-container > div.normal_text_dv')->count() > 0) { + $crawler->filter('.elementor-widget-container > div.normal_text_dv, div.normal_text_dv > p')->each(function ($node) { - if($crawler->filter('span[class*="elementor-icon-list-text elementor-post-info__item elementor-post-info__item--type-author"]')->count() == 1) - { + // Check if any alphabet exist. (To ignore the ads in articles) + if (preg_match('/[a-zA-Z]/', $node->text())) { + return; + } + $this->content[] = preg_replace("/[a-zA-Z]/", "", $node->text()); + }); + } else { + $crawler->filter('.elementor-widget-container > p')->each(function ($node) { + $this->content[] = preg_replace("/[a-zA-Z]/", "", $node->text()); + }); + } + + + + if ($crawler->filter('span[class*="elementor-icon-list-text elementor-post-info__item elementor-post-info__item--type-author"]')->count() == 1) { $this->author = $crawler->filter('span[class*="elementor-icon-list-text elementor-post-info__item elementor-post-info__item--type-author"]')->first()->text(); } - + //Remove all the alphabets from string //preg_replace("/[a-zA-Z]/", "",$string); - return [ + return [ 'source' => 'Dhuvas', 'title' => $this->title, 'og_title' => $crawler->filter('meta[property*="og:title"]')->first()->attr('content'), @@ -49,7 +62,7 @@ class DhuvasScraper 'content' => $this->content, 'url' => $url, 'date' => Carbon::parse($date)->format("Y-m-d H:i:s"), - 'guid' => str_replace("https://dhuvas.mv/","",$url), + 'guid' => str_replace("https://dhuvas.mv/", "", $url), 'author' => $this->author, 'topics' => [ [