'https://api.ujeebu.com/guess-er', CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_HTTPHEADER => [ 'ApiKey: ' . $apiKey, 'Content-Type: application/json' ], CURLOPT_POSTFIELDS => json_encode([ 'url' => $url, 'prompt' => $prompt, 'provider' => 'openai', 'model' => 'gpt-4o-mini' ]) ]); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($httpCode === 200) { $data = json_decode($response, true); return $data['extract_rules'] ?? null; } return null; } // Generate rules $rules = generateExtractRules( 'https://store.example.com/products', 'Extract product name, price, image, and rating' ); if ($rules) { echo "Generated rules:\n"; echo json_encode($rules, JSON_PRETTY_PRINT) . "\n"; // Step 2: Use rules for fast, free scraping $ch = curl_init(); curl_setopt_array($ch, [ CURLOPT_URL => 'https://api.ujeebu.com/scrape', CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_HTTPHEADER => [ 'ApiKey: ' . getenv('UJEEBU_API_KEY'), 'Content-Type: application/json' ], CURLOPT_POSTFIELDS => json_encode([ 'url' => 'https://store.example.com/products', 'extract_rules' => $rules, 'js' => true, 'response_type' => 'json' ]) ]); $response = curl_exec($ch); $data = json_decode($response, true); curl_close($ch); $products = $data['products'] ?? []; echo "\nExtracted " . count($products) . " products without AI cost!\n"; } ?>