client = new Client; } public function extract($url, $date) { $crawler = $this->client->request('GET', $url); $crawler->filter('.body > p')->each(function ($node) { $this->content[] = $node->text(); }); if ($crawler->filter('.author_name')->count() > 0) { $this->author = $crawler->filter('.author_name')->first()->text(); } $crawler->filter('.article-tags a')->each(function ($node) { $this->topics[] = [ "name" => $node->text(), "slug" => str_replace("https://hama.mv/", "", $node->attr('href')) ]; }); //Remove all the alphabets from string //preg_replace("/[a-zA-Z]/", "",$string); return [ 'source' => 'Hama', 'title' => $crawler->filter('h1')->first()->text(), 'og_title' => $crawler->filter('meta[property*="og:title"]')->first()->attr('content'), 'image' => $crawler->filter("figure > img")->first()->attr('data-src'), 'content' => $this->content, 'url' => $url, 'date' => Carbon::parse($date)->format("Y-m-d H:i:s"), 'guid' => basename($url), 'author' => $this->author, 'topics' => $this->topics ]; } }