Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const utils = require('../utils')
- const axios = require('axios')
- /**
- * Получаем текст капчи с помощью API anti-captcha.com
- * @rapam url - ссылка на изображение
- * @return [error, solution] - ошибка и решение капчи
- */
- exports.getCaptcha = async function(url) {
- // Получаем картинку
- var response = await axios(url, {responseType: 'arraybuffer'});
- // Параметры для создания задачи
- var params = {
- "clientKey":"...",
- "task": {
- "type": "ImageToTextTask",
- "body": Buffer.from(response.data, 'binary').toString('base64'),
- "phrase": false,
- "case": false,
- "numeric": 0,
- "math": 0,
- "minLength": 0,
- "maxLength": 0
- }
- }
- // Создаем задачу
- const task = await axios.post('https://api.anti-captcha.com/createTask', params);
- taskId = task.data.taskId
- // Ждем 5 секунд
- await utils.sleep(5000)
- // Параметры для проверки статуса задачи
- var params = {
- "clientKey":"...",
- "taskId": taskId
- }
- // Пока не получим ответ - будем спрашивать результат каждую секунду
- while (true) {
- var response = await axios.post('https://api.anti-captcha.com/getTaskResult', params);
- console.log(response.data)
- // Если получен ответ
- if (response.data.status == 'ready') {
- return [null, response.data.solution.text];
- }
- await utils.sleep(1000)
- }
- }
Advertisement