ImageToTextTask : giải một mã captcha hình ảnh
Đăng nội dung hình ảnh và nhận văn bản từ ảnh đó. Văn bản chỉ có thể chứa chữ số, chữ cái, ký tự đặc biệt và một dấu cách. Hệ thống có hỗ trợ ảnh động GIF, lên đến 500kb. Hệ thống không hỗ trợ mã captcha tùy chỉnh như "tìm một con mèo trên bộ hình ảnh này và nhập số của con mèo".
Đối tượng tác vụ
Thuộc tính | Loại | Bắt buộc | Giá trị mặc định | Mục đích |
---|---|---|---|---|
type | Chuỗi | Có | ImageToTextTask | Xác định một loại tác vụ. |
body | Chuỗi | Có | Nội dung tệp được mã hóa trong base64. Đảm bảo gửi nội dung tệp không ngắt dòng. Không chứa 'data:image/png,' hoặc các tag tương tự, chỉ duy nhất base64! | |
phrase | Boolean | Không | false | sai - không yêu cầu đúng - nhân viên phải nhập câu trả lời có ít nhất một "dấu cách". Nếu không có dấu cách, nhân viên sẽ bỏ qua tác vụ, vì vậy hãy sử dụng các tag một cách thận trọng. |
case | Boolean | Không | true | sai - không yêu cầu đúng - nhân viên sẽ thấy một dấu đặc biệt cho biết rằng câu trả lời phải phân biệt chữ hoa chữ thường. |
numeric | Số nguyên | Không | 0 | 0 - không yêu cầu 1 - chỉ được dùng số 2 - được dùng mọi chữ cái trừ số |
math | Boolean | Không | false | sai - không yêu cầu đúng - nhân viên sẽ thấy một dấu đặc biệt cho biết rằng câu trả lời phải được tính toán. |
minLength | Số nguyên | Không | 0 | 0 - không yêu cầu >1 - xác định độ dài câu trả lời tối thiểu |
maxLength | Số nguyên | Không | 0 | 0 - không yêu cầu >1 - xác định độ dài câu trả lời tối đa |
comment | Chuỗi | Không | Nhận xét bổ sung cho nhân viên như "nhập chữ cái bằng màu đỏ". Kết quả không được đảm bảo và hoàn toàn phụ thuộc vào nhân viên. | |
websiteURL | Chuỗi | Không | Tham số tùy chọn để phân biệt nguồn của mã captcha hình ảnh trong số liệu thống kê chi tiêu. |
Ví dụ về yêu cầu
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);
}
}
}
Ví dụ về phản hồi
JSON không lỗi
{
"errorId": 0,
"taskId": 7654321
}
JSON có lỗi
{
"errorId": 1,
"errorCode": "ERROR_KEY_DOES_NOT_EXIST",
"errorDescription": "Account authorization key not found in the system"
}
Truy xuất lời giải
Sử dụng phương thức getTaskResult để yêu cầu giải. Cho nhân viên một khoảng thời gian, chẳng hạn như 5 giây, trước khi tạo yêu cầu đầu tiên. Nếu nhân viên vẫn bận, hãy thử lại sau 3 giây.
Đối tượng giải của tác vụ
Thuộc tính | Loại | Mục đích |
---|---|---|
text | Chuỗi | Văn bản từ mã captcha hình ảnh |
url | Chuỗi | Địa chỉ web của captcha, nơi chúng tôi sẽ lưu trữ trong 24 giờ tới. Sau 24 giờ, captcha sẽ bị gỡ bỏ. |
Ví dụ về phản hồi
JSON không lỗi
{
"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"
}