diff --git a/app/Services/Scrapers/AvasScraper.php b/app/Services/Scrapers/AvasScraper.php index 6f2e4c5..dd5f247 100644 --- a/app/Services/Scrapers/AvasScraper.php +++ b/app/Services/Scrapers/AvasScraper.php @@ -1,5 +1,4 @@ client = new Client; @@ -25,18 +25,20 @@ class AvasScraper $title = $crawler->filter('h1')->first()->text(); - - - $image = ($crawler->filter('figure img')->first()->attr('src')) ? $crawler->filter('figure img')->first()->attr('src') : "/images/noimg.jpg"; + if($crawler->filter('figure img')->count() == 1) + { + $this->image = $crawler->filter('figure img')->first()->attr('src'); + } $crawler->filter('.post_content p')->each(function ($node) { - $this->content[] = preg_replace("/[a-zA-Z]/", "", $node->text()); + $this->content[] = preg_replace("/[a-zA-Z]/","",$node->text()); }); $crawler->filter('div[class*="border-t border-grey-light border-dotted mt-7 py-3"] a')->each(function ($node) { - + //Removing the show more tags button - if ($node->text() == "+") { + if($node->text() == "+") + { return; } $this->topics[] = [ @@ -45,26 +47,27 @@ class AvasScraper ]; }); + - - if ($crawler->filter('div[class*="font-waheed text-grey ml-3 pl-3 text-lg border-l border-grey border-dotted"] a')->count() == 1) { + if($crawler->filter('div[class*="font-waheed text-grey ml-3 pl-3 text-lg border-l border-grey border-dotted"] a')->count() == 1) + { $this->author = $crawler->filter('div[class*="font-waheed text-grey ml-3 pl-3 text-lg border-l border-grey border-dotted"] a')->first()->text(); } //Remove all the alphabets from string //preg_replace("/[a-zA-Z]/", "",$string); - return [ + return [ 'source' => 'Avas', 'title' => $title, 'og_title' => $crawler->filter('meta[property*="og:title"]')->first()->attr('content'), - 'image' => $image, + 'image' => $this->image, 'content' => $this->content, 'url' => $url, 'date' => Carbon::parse($crawler->filter('timeago')->first()->attr('datetime'))->format("Y-m-d H:i:s"), - 'guid' => str_replace("https://avas.mv/", "", $url), + 'guid' => str_replace("https://avas.mv/","",$url), 'author' => $this->author, 'topics' => $this->topics ]; } -} +} \ No newline at end of file