client = new Client( HttpClient::create([ "proxy" => config('karudhaas.proxy.host') ]) ); } public function extract($url, $date = null) { $crawler = $this->client->request('GET', $url); // Extract title $this->title = $crawler->filter('h1.font-52')->first()->text(); // Extract image URL $this->image = $crawler->filter('img.img-fluid.hero-img')->first()->attr('src'); $authorNode = $crawler->filter('.MuiAvatar-circle img'); if ($authorNode->count() > 0) { $this->author = $authorNode->first()->attr('alt'); } else { $this->author = 'unknown'; // Set to 'Unknown' if author element is not found } // Extract content $crawler->filter('.body > p')->each(function ($node) { $this->content[] = $node->text(); }); // Extract topics (tags) $crawler->filter('a[href^="/tags/"]')->each(function ($node) { $href = $node->attr('href'); $slug = basename($href); // Extracts the last segment of the URL $this->topics[] = [ "name" => trim($node->filter('.tag')->first()->text()), "slug" => Str::slug($slug) ]; }); return [ 'source' => 'Adhadhu', 'title' => $this->title, 'og_title' => $crawler->filter('meta[property*="og:title"]')->first()->attr('content'), 'image' => $this->image, 'content' => $this->content, 'url' => $url, 'date' => $date, 'guid' => basename($url), 'author' => $this->author, 'topics' => $this->topics ]; } }