Repository navigation
Expand file tree
/
Copy pathyandex_smartcaptcha_image.js
More file actions
38 lines (32 loc) · 1.63 KB
/
Copy pathyandex_smartcaptcha_image.js
File metadata and controls
38 lines (32 loc) · 1.63 KB
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
import 'dotenv/config';
import fs from 'fs';
import { CaptchaClient, Tasks } from '@captcha-solver-api/javascript-sdk';
/**
* Solve a Yandex SmartCaptcha image challenge from local assets.
* It creates Tasks.YandexSmartCaptchaImageTask from the shown parameters, submits it with
* CaptchaClient.solve(), and prints the relevant returned value. Applying that value to a
* target page is site-specific. Replace all target-specific placeholders before running.
*
* How it works:
* STEP-01 - Configure the SDK client.
* STEP-02 - Create the CAPTCHA task from the required parameters or local assets.
* STEP-03 - Submit the task and wait for CaptchaClient.solve() to return the solution.
* STEP-04 - Print the relevant solution value or report an error.
*/
// STEP-01: Configure the SDK client with the API key.
const client = new CaptchaClient({ clientKey: process.env.CAPTCHA_API_KEY || 'YOUR_API_KEY' });
// STEP-02: Create the CAPTCHA task with the values required by this challenge.
const task = new Tasks.YandexSmartCaptchaImageTask({
image: fs.readFileSync(new URL('./assets/yandex-smartcaptcha-image.png', import.meta.url)).toString('base64'),
imgInstructions: fs.readFileSync(new URL('./assets/yandex-smartcaptcha-instructions.png', import.meta.url)).toString('base64')
});
// STEP-03: Submit the task; solve() handles task creation and polling.
client.solve(task)
.then((solution) => {
// STEP-04: Print only the useful field returned for this CAPTCHA type.
console.log(solution.coordinates);
})
.catch((error) => {
// Report SDK or transport failures without hiding the rejected Promise.
console.error(error);
});