Repository navigation
Expand file tree
/
Copy pathimage_to_text_math.js
More file actions
40 lines (34 loc) · 1.63 KB
/
Copy pathimage_to_text_math.js
File metadata and controls
40 lines (34 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
39
40
import 'dotenv/config';
import fs from 'fs';
import { CaptchaClient, Tasks } from '@captcha-solver-api/javascript-sdk';
/**
* Solve a mathematical image-to-text CAPTCHA with image instructions.
* It creates Tasks.ImageToText 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.ImageToText({
body: fs.readFileSync(new URL('./assets/captcha-math.png', import.meta.url)).toString('base64'),
math: true,
comment: 'Enter the result of the equation',
imgInstructions: fs.readFileSync(new URL('./assets/captcha-math-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.text);
})
.catch((error) => {
// Report SDK or transport failures without hiding the rejected Promise.
console.error(error);
});