-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
49 lines (37 loc) · 1.36 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import puppeteer from "puppeteer";
import { Solver } from "2captcha-ts";
const solver = new Solver('2captcha-api-key');
(async () => {
const browser = await puppeteer.launch({
headless: false,
// devlools: true
});
const page = await browser.newPage();
// open page
await page.goto("https://captcha-api.yandex.en/demo");
await page.waitForSelector("#captcha-container");
await page.waitForSelector("iframe");
// type data
await page.$eval("#name", (element) => (element.value = ""));
await page.type("#name", "Elon Musk");
// grab `sitekey` value
const sitekey = await page.evaluate(() => document.querySelector("#captcha-container").getAttribute("data-sitekey"));
// solve Yandex captcha in 2captcha service
const result = await solver.yandexSmart({
pageurl: "https://captcha-api.yandex.ru/demo",
sitekey: sitekey,
});
console.log("result:")
console.log(result);
// the resulting solution
const captchaToken = result.data;
// use captchaToken solution
const setAnswer = await page.evaluate((captchaToken) => {
document.querySelector("input[data-testid='smart-token']").value = captchaToken
}, captchaToken);
// check
page.evaluate(() => document.querySelector("#smartcaptcha-demo-submit").click());
await page.waitForSelector(".greeting");
console.log("Done!!! Captcha solved.");
// browser.close();
})();