Puppeteer Intégration
Puppeteer + CaptchaSonic
Résolution transparente des CAPTCHA pour vos workflows d'automatisation Puppeteer et de web scraping.
npm
Installation rapide
npm install captchasonic puppeteer01
Configurer le solveur
Importez Puppeteer et initialisez le client CaptchaSonic.
import puppeteer from 'puppeteer';
import { CaptchaSonic } from 'captchasonic';
// Solves over a native gRPC connection (no HTTP overhead)
const client = new CaptchaSonic(process.env.CAPTCHASONIC_API_KEY);02
Lancer le navigateur et naviguer
Ouvrez une instance de navigateur et accédez à la page cible.
const browser = await puppeteer.launch({
headless: false,
args: ['--no-sandbox']
});
const page = await browser.newPage();
await page.goto('https://example.com/protected-page', {
waitUntil: 'networkidle2'
});03
Détecter et résoudre le CAPTCHA
Identifiez le type de CAPTCHA, extrayez les paramètres et résolvez-le.
// Find the captcha sitekey
const sitekey = await page.$eval(
'.g-recaptcha', el => el.getAttribute('data-sitekey')
);
// Send to CaptchaSonic for solving over gRPC
const result = await client.solveRecaptchaV2Token({
websiteURL: page.url(),
websiteKey: sitekey,
});
const token = result.solution.gRecaptchaResponse;04
Appliquer le jeton et poursuivre
Injectez le jeton de solution et déclenchez l'envoi du formulaire.
// Set the response
await page.evaluate((token) => {
document.getElementById('g-recaptcha-response')
.innerHTML = token;
// Trigger callback if exists
if (typeof ___grecaptcha_cfg !== 'undefined') {
Object.values(___grecaptcha_cfg.clients)
.forEach(c => c.callback(token));
}
}, token);
// Wait for navigation after captcha solve
await page.waitForNavigation({ timeout: 10000 });
console.log('Captcha solved successfully!');Links
Ressources associées
Prêt à automatiser ?
Obtenez votre clé API et commencez à résoudre des CAPTCHA en quelques minutes. $0.50 de crédits bonus offerts.
Obtenir une clé API