ImageToTextTask:破解图片人机验证谜题
公开提供图片主体,然后会收到其中的文本。文本仅可包含数字、字母、特殊字符和空格。GIF 动画受支持,最大 500kb。“在这些图片中找到猫,然后输入其编号”之类的自定义人机验证谜题不受支持。
任务对象
属性 | 类型 | 必须使用 | 默认值 | 用途 |
---|---|---|---|---|
type | 字符串 | 是 | ImageToTextTask | 指定任务类型。 |
body | 字符串 | 是 | 文件主体以 base64 方式编码。一定要在没有换行符的情况下发送文件主体。不要包括“data:image/png”或类似的标记,仅使用纯净的 base64 格式! | |
phrase | 布尔值 | 否 | false | false - 没有要求 true - 工作人员必须输入至少有一个“空格”的答案。如果没有空格,则工作人员会略过相应任务,因此使用时要谨慎。 |
case | 布尔值 | 否 | true | false - 没有要求 true - 工作人员会看到特殊标志,告知输入的答案必须区分大小写。 |
numeric | 整数 | 否 | 0 | 0 - 没有要求 1 - 只许输入数字 2 - 除了数字,可以输入任何字母 |
math | 布尔值 | 否 | false | false - 没有要求 true - 工作人员会看到特殊标志,告知必须算出答案 |
minLength | 整数 | 否 | 0 | 0 - 没有要求 >1 - 指定答案长度下限 |
maxLength | 整数 | 否 | 0 | 0 - 没有要求 >1 - 指定答案长度上限 |
comment | 字符串 | 否 | 面向工作人员的其他注释,如“以红色输入字母”。 结果没有保证,完全取决于工作人员。 | |
websiteURL | 字符串 | 否 | 自愿使用的参数,用于在支出统计数据中区分图片人机验证谜题来源。 |
请求示例
CURL
curl -i -H "Accept: application/json" \
-H "Content-Type: application/json" \
-X POST -d '{
"clientKey":"YOUR_API_KEY_HERE",
"task":
{
"type":"ImageToTextTask",
"body":"BASE64_BODY_HERE__NO_NEWLINES__NO_EXTRA_TAGS__ONLY_CLEAN_BASE64",
"phrase":false,
"case":false,
"numeric":0,
"math":false,
"minLength":0,
"maxLength":0
},
"softId": 0
}' https://api.anti-captcha.com/createTask
PHP
<?php
//git clone git@github.com:AdminAnticaptcha/anticaptcha-php.git
include("anticaptcha.php");
include("imagetotext.php");
$api = new ImageToText();
//your anti-captcha.com account key
$api->setKey("YOUR_API_KEY_HERE");
//setting file
$api->setFile("captcha.jpg");
//Specify softId to earn 10% commission with your app.
//Get your softId here: https://anti-captcha.com/clients/tools/devcenter
$api->setSoftId(0);
//create task in API
if (!$api->createTask()) {
echo "API v2 send failed - ".$api->getErrorMessage()."\n";
exit;
}
$taskId = $api->getTaskId();
if (!$api->waitForResult()) {
echo "could not solve captcha\n";
echo $api->getErrorMessage()."\n";
} else {
$captchaText = $api->getTaskSolution();
echo "captcha text: $captchaText\n\n";
}
Python
#pip3 install anticaptchaofficial
from anticaptchaofficial.imagecaptcha import *
solver = imagecaptcha()
solver.set_verbose(1)
solver.set_key("YOUR_API_KEY_HERE")
# Specify softId to earn 10% commission with your app.
# Get your softId here: https://anti-captcha.com/clients/tools/devcenter
solver.set_soft_id(0)
captcha_text = solver.solve_and_return_solution("captcha.jpeg")
if captcha_text != 0:
print "captcha text "+captcha_text
else:
print "task finished with error "+solver.error_code
NodeJS
//npm install @antiadmin/anticaptchaofficial
//https://github.com/AdminAnticaptcha/anticaptcha-npm
const ac = require("@antiadmin/anticaptchaofficial");
const fs = require('fs');
const captcha = fs.readFileSync('captcha.png', { encoding: 'base64' });
ac.setAPIKey('YOUR_API_KEY_HERE');
//Specify softId to earn 10% commission with your app.
//Get your softId here: https://anti-captcha.com/clients/tools/devcenter
ac.setSoftId(0);
ac.solveImage(captcha, true)
.then(text => console.log('captcha text: '+text))
.catch(error => console.log('test received error '+error));
C#
//git clone git@github.com:AdminAnticaptcha/anticaptcha-csharp
using System;
using Anticaptcha_example.Api;
using Anticaptcha_example.Helper;
using Newtonsoft.Json.Linq;
namespace Anticaptcha_example
{
internal class Program
{
private static void Main() {
DebugHelper.VerboseMode = true;
var api = new ImageToText
{
ClientKey = "YOUR_API_KEY_HERE",
FilePath = "captcha.jpg",
// Specify softId to earn 10% commission with your app.
// Get your softId here:
// https://anti-captcha.com/clients/tools/devcenter
SoftId = 0
};
if (!api.CreateTask())
DebugHelper.Out("API v2 send failed. " + api.ErrorMessage, DebugHelper.Type.Error);
else if (!api.WaitForResult())
DebugHelper.Out("Could not solve the captcha.", DebugHelper.Type.Error);
else
DebugHelper.Out("Result: " + api.GetTaskSolution().Text, DebugHelper.Type.Success);
}
}
}
Java
//git clone git@github.com:AdminAnticaptcha/anticaptcha-java.git
package com.anti_captcha;
import com.anti_captcha.Api.ImageToText;
import com.anti_captcha.Helper.DebugHelper;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Iterator;
import java.util.concurrent.ThreadLocalRandom;
public class Main {
public static void main(String[] args) throws InterruptedException, MalformedURLException, JSONException {
DebugHelper.setVerboseMode(true);
ImageToText api = new ImageToText();
api.setClientKey("YOUR_API_KEY_HERE");
api.setFilePath("captcha.jpg");
//Specify softId to earn 10% commission with your app.
//Get your softId here: https://anti-captcha.com/clients/tools/devcenter
api.setSoftId(0);
if (!api.createTask()) {
DebugHelper.out(
"API v2 send failed. " + api.getErrorMessage(),
DebugHelper.Type.ERROR
);
} else if (!api.waitForResult()) {
DebugHelper.out("Could not solve the captcha.", DebugHelper.Type.ERROR);
} else {
DebugHelper.out("Result: " + api.getTaskSolution().getText(), DebugHelper.Type.SUCCESS);
}
}
}
回应示例
JSON 没有错误
{
"errorId": 0,
"taskId": 7654321
}
JSON 有错误
{
"errorId": 1,
"errorCode": "ERROR_KEY_DOES_NOT_EXIST",
"errorDescription": "Account authorization key not found in the system"
}
重获破解结果
用方法 getTaskResult 请求提供破解结果。首次提出请求之前,要给工作人员一些时间,例如 5 秒钟。如果工作人员还在忙,则过 3 秒再重试。
任务破解结果对象
属性 | 类型 | 用途 |
---|---|---|
text | 字符串 | 图片人机验证谜题中的文本 |
url | 字符串 | 人机验证谜题网址,我们将在未来的 24 小时内从中存储人机验证谜题。这段时间过后会将其删除。 |
回应示例
JSON 没有错误
{
"errorId":0,
"status":"ready",
"solution":
{
"text":"deditur",
"url":"http://61.39.233.233/1/147220556452507.jpg"
},
"cost":"0.000700",
"ip":"46.98.54.221",
"createTime":1472205564,
"endTime":1472205570,
"solveCount":"0"
}