Scraper avec Node.js

Node.js 18+ inclut fetch nativement : aucune dépendance nécessaire pour appeler WyndPath.

Installation

Node 18 ou plus récent : fetch est déjà disponible. Sinon : npm install node-fetch.

Premier appel

const params = new URLSearchParams({
  api_key: "VOTRE_CLE",
  url: "https://exemple.com",
});

const resp = await fetch(`https://api.wyndpath.com/v1/?${params}`);
console.log(resp.status);          // code HTTP de la cible
console.log(await resp.text());    // contenu brut

Rendu JavaScript et pays

const params = new URLSearchParams({
  api_key: "VOTRE_CLE",
  url: "https://exemple.com",
  render_js: "1",
  country: "fr",
  max_cost: "15",
});
const resp = await fetch(`https://api.wyndpath.com/v1/?${params}`);

Lire les crédits

console.log(resp.headers.get("x-wyndpath-credits"));

Requête POST

const params = new URLSearchParams({ api_key: "VOTRE_CLE", url: "https://exemple.com/api" });
const resp = await fetch(`https://api.wyndpath.com/v1/?${params}`, {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ q: "pikachu" }),
});

Gérer les erreurs

if (resp.ok) {
  const html = await resp.text();
} else {
  const err = await resp.json();
  console.error("Erreur", resp.status, err.error);
}
✓ Payé au succès. Un appel qui échoue ne consomme aucun crédit.