Skip to content

Instantly share code, notes, and snippets.

@ofarukcaki
Created August 5, 2019 15:21
Show Gist options
  • Save ofarukcaki/169d639cd2513a9cfaff0b9489c51c6b to your computer and use it in GitHub Desktop.
Save ofarukcaki/169d639cd2513a9cfaff0b9489c51c6b to your computer and use it in GitHub Desktop.
const puppeteer = require("puppeteer");
const captcha = require("async-captcha");
const anticaptcha = new captcha("YOUR_API_KEY", 2, 10); // (api_key, interval(seconds), retry(amount))
(async () => {
const browser = await puppeteer.launch({
headless: false,
defaultViewport: false
});
const page = (await browser.pages())[0];
// imaginary page with a captcha on it
await page.goto(
"https://example.com/captcha-page",
{ waitUntil: "load" }
);
const elementHandler = await page.$("#captcha-container img");
// base64String contains the captcha image's base64 encoded version
const base64String = await elementHandler.screenshot({ encoding: "base64" });
const captchaCode = await anticaptcha.getResult(base64String);
// captchaCode contains your solved captcha as a String
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment