'https://api.ujeebu.com/scrape?' . http_build_query(['url' => $url]), CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => ['ApiKey: ' . $apiKey] ]); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($httpCode !== 200) { return null; } $data = json_decode($response, true); return $data['html'] ?? $data['text'] ?? ''; } // Scrape and parse HTML $html = scrapePage('https://www.wired.com'); if ($html) { $dom = new DOMDocument(); @$dom->loadHTML($html); $xpath = new DOMXPath($dom); // Extract article titles $articles = []; $nodes = $xpath->query("//tr[@class='athing']"); foreach ($nodes as $node) { $titleNode = $xpath->query(".//span[@class='titleline']/a", $node)->item(0); if ($titleNode) { $articles[] = [ 'title' => $titleNode->textContent, 'url' => $titleNode->getAttribute('href'), 'id' => $node->getAttribute('id') ]; } } // Display results foreach (array_slice($articles, 0, 10) as $idx => $article) { echo ($idx + 1) . ". " . $article['title'] . "\n"; echo " " . $article['url'] . "\n\n"; } } ?>