Grid Method
The method can be used to bypass tasks where a grid is applied to an image and you need to click on grid tiles, like reCAPTCHA images.
Returns the array of tile indexes, where 1 is top left tile.
Supported image formats: JPEG, PNG, GIF
Max file size: 600 kB
Max image size: 1000px on any side
GridTask task type specification
Property | Type | Required | Description |
---|---|---|---|
type | String | Yes | GridTask |
body | String | Yes | Image encoded into Base64 format. Data-URI format (containing data:content/type prefix) is also supported |
rows | Integer | No | Number of grid rows |
columns | Integer | No | Number of grid columns |
comment | String | Yes* | A comment will be shown to workers to help them to solve the captcha properly |
imgInstructions | String | Yes* | An image with instruction that will be shown to workers. Image should be encoded into Base64 format. Max file size: 100 kB |
previousId | String | No | Id of your previous request with the same captcha challenge |
imgType | String | No | The image will be recognized using Computer Vision, which significantly reduces the time needed to solve the captcha. Supported value options: funcaptcha - sending FunCaptcha, the version in which you need to click on the square matching the requirements. More info here.funcaptcha_compare - sending FunCaptcha, a version in which you need to use the arrows to select the desired square. More info here.recaptcha - sending reCAPTCHA. More info here.Important: when using the imgType parameter, it is required to send the comment parameter containing the original instructions for the captcha in English, and you also need to send the original image files and not screenshots. |
previousId | String | No | Id of your previous request with the same captcha challenge |
minClicks | Integer | No | The minimum number of tiles that must be selected. Default: 1 . Can't be more than rows * columns |
maxClicks | Integer | No | The maximum number of tiles that can be selected on the image. Default: rows * columns |
canNoAnswer | Integer | No | 0 - not specified 1 - possibly there's no images that fit the instruction. Set the value to 1 only if it's possible that there's no images matching to the instruction. We'll provide a button "No matching images" to worker and you will receive No_matching_images as answer. |
- you should provide at least one of the properties:
comment
orimgInstructions
Request example
Method: createTask
API endpoint: https://api.2captcha.com/createTask
{
"clientKey":"YOUR_API_KEY",
"task": {
"type":"GridTask",
"body":"/9j/4AAQSkZJRgABAQAAAQ..HIAAAAAAQwAABtbnRyUkdCIFhZ.wc5GOGSRF//Z",
"comment":"select all vehicles",
"rows": 4,
"columns": 4
}
}
Response example
Method: getTaskResult
API endpoint: https://api.2captcha.com/getTaskResult
{
"errorId": 0,
"status": "ready",
"solution": {
"click": [
4,
8,
12,
16
]
},
"cost": "0.0012",
"ip": "1.2.3.4",
"createTime": 1692863536,
"endTime": 1692863556,
"solveCount": 1
}
Code examples
// https://github.com/2captcha/2captcha-php
require(__DIR__ . '/../src/autoloader.php');
$solver = new \TwoCaptcha\TwoCaptcha('YOUR_API_KEY');
try {
$result = $solver->grid('path/to/captcha.jpg');
} catch (\Exception $e) {
die($e->getMessage());
}
die('Captcha solved: ' . $result->code);
# https://github.com/2captcha/2captcha-python
import sys
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
from twocaptcha import TwoCaptcha
api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
solver = TwoCaptcha(api_key)
try:
result = solver.grid('path/to/captcha.jpg')
except Exception as e:
sys.exit(e)
else:
sys.exit('solved: ' + str(result))
// https://github.com/2captcha/2captcha-csharp
using System;
using System.Linq;
using TwoCaptcha.Captcha;
namespace TwoCaptcha.Examples
{
public class GridExample
{
public static void Main()
{
var solver = new TwoCaptcha("YOUR_API_KEY");
Grid captcha = new Grid("path/to/captcha.jpg");
try
{
solver.Solve(captcha).Wait();
Console.WriteLine("Captcha solved: " + captcha.Code);
}
catch (AggregateException e)
{
Console.WriteLine("Error occurred: " + e.InnerExceptions.First().Message);
}
}
}
}
// https://github.com/2captcha/2captcha-java
package examples;
import com.twocaptcha.TwoCaptcha;
import com.twocaptcha.captcha.Grid;
public class GridExample {
public static void main(String[] args) {
TwoCaptcha solver = new TwoCaptcha("YOUR_API_KEY");
Grid captcha = new Grid("path/to/captcha.jpg");
try {
solver.solve(captcha);
System.out.println("Captcha solved: " + captcha.getCode());
} catch (Exception e) {
System.out.println("Error occurred: " + e.getMessage());
}
}
}
// https://github.com/2captcha/2captcha-go
package main
import (
"fmt"
"log"
"github.com/2captcha/2captcha-go"
)
func main() {
client := api2captcha.NewClient("API_KEY")
captcha := api2captcha.Grid{
File: "/path/to/captcha.jpg",
}
code, err := client.Solve(captcha.ToRequest())
if err != nil {
log.Fatal(err);
}
fmt.Println("code "+code)
}
require 'api_2captcha'
client = Api2Captcha.new("YOUR_API_KEY")
result = client.grid({ image: 'path/to/captcha.jpg'})
# OR
result = client.grid({
image: 'https://site-with-captcha.com/path/to/captcha.jpg'
})