AntiCaptcha2 🤖
A simple NodeJS package for solving almost all types of captchas using https://anti-captcha.com
Table of contents
Features
- Simple to use.
- Solving almost all types of captcha (reCAPTCHA, GeeTest, FunCaptcha, Classic image to text, SquareNetTextTask).
- Easy creating and solving custom tasks.
- Support Proxy
- Full ...???
API key
Before using this package you should recharge the balance and get API-key. Step by step:
- Create account at anti-captcha.com.
- Recharge the balance (Finance > Add Funds).
- Create API-key (Settings > API setup).
- That's all.
Anticaptcha
[TODO: add text]
new Anticaptcha(apikey, [proxy])
The class creates an object that wraps the anti-captcha API.
apikey
- API key, which can be obtained in account settings
proxy
- is an optional parameter that specifies the default proxy. See Proxy
.
const Anticaptcha = ;const Proxy = AnticaptchaProxy; let anticaptcha = 'API_KEY' ...;
anticaptcha.getProxy()
Method to get the default proxy. If no proxy is specified, it will return null
.
anticaptcha.setProxy(proxy)
Method to set the default proxy.
proxy
- either an instance of the class Proxy
or an object with parameters like the class of Proxy
anticaptcha.method(method, [data, [isPrivate]])
Method for calling the custom anti-captcha API method. Returns Promise
.
method
- string method namedata
- object with data. (Default:{}
)isPrivate
- whether you need to add an api-key to the request. Only needed for private methods. (Default:false
)
anticaptcha.getBalance()
Method to fetch account balance. Returns Promise
.
anticaptcha ;
anticaptcha.getQueueStats(queueId)
This method allows to define if it is suitable time to upload new task. Results are cached for 10 seconds. Returns Promise
.
queueId
- id of the queue. The following queues are available:
- 1 - standart ImageToText, English language
- 2 - standart ImageToText, Russian language
- 5 - Recaptcha NoCaptcha tasks
- 6 - Recaptcha Proxyless task
- 7 - Funcaptcha
- 10 - Funcaptcha Proxyless
anticaptcha ;
Response:
Field | Description |
---|---|
waiting |
Amount of idle workers online, waiting for a task |
load |
Queue load in percents |
bid |
Average task solution cost in USD |
speed |
Average task solution speed in seconds |
total |
Total number of workers |
anticaptcha.solve(task, [opts])
It's a fast and simple alias for methods anticaptcha.createTask(task, opts) and anticaptcha.getTaskResult(taskId).
anticaptcha.createTask(task, [opts])
This method creates a task for solving selected captcha type. Returns ID of the created task.
task
- task-object (plain object with key-values) orTask
instance.opts
- optionalobject
with extra params:softId
- ID of your application from out AppCenterlanguagePool
- Sets workers pool language. At the moment the following language pools are available:
en (default) - English language queue
rn : group of countries: Russia, Ukraine, Belarus, KazahstancallbackUrl
- web address were will send result of captcha/factory task processing. Contents are sent by AJAX POST request and are similar to the contents ofanticaptcha.getTaskResult
method.
anticaptcha.getTaskResult(taskId, [opts])
Request task result. If the task is not completed, the status
will be processing
. Returns Promise
.
taskId
- ID of the task.opts
- optionalobject
with extra params:extended
- Iftrue
method will return extended result of task (withcost
,ip
et.c.). Otherwise - onlysolution
. (Default:false
)wait
- set totrue
to wait for a solution of the task. (Default:false
)waitTime
- ifwait
istrue
, then this parameter can specify timeouts to check the result of the task. It's an 2-elementsarray
: first element - first request delay, second - second and next request. Numbers inms
. (Defaults:[5000, 2000]
)
// Task is not readyanticaptcha; // Task is not readyanticaptcha; // Task is readyanticaptcha; // Task is readyanticaptcha; // Waiting// The promise will be fulfilled when the status of the task is "fulfilled".// By default first try in 5 sec, second and next - in 2 sec.anticaptcha; // Waiting// You can set timeouts. In this example: 1st - 2 sec, 2nd and next = 1 sec.anticaptcha;
anticaptcha.reportIncorrectImageCaptcha(taskId)
Complaints are accepted only for image captchas. Your complaint will be checked by 5 workers, 3 of them must confirm it. Only then you get full refund. Note: If you have less than 20% confirmation ratio, your reports will be ignored.
anticaptcha.test(data)
This method reads request data, parses it and outputs as array. It also outputs post data in a raw format. You may use it for debugging your code.
data
- anything (string/number/object/array
)
anticaptcha;
Proxy
At the moment almost all captcha services do not have protection from situations when the puzzle is solved on one IP address and form with captcha-response is submitted from another IP.
const Proxy = Proxy; let proxy = type: 'http' address:'8.8.8.8' port: '8080' agent: 'Mozilla/5.0 ...';
new Proxy(opts)
The constructor will not check the required fields. This is done so that you later set some fields (see Proxy.checkProxy()
)
Name | Type | Required | Description |
---|---|---|---|
type |
String |
true |
Type of proxy.
|
address |
String |
true |
Proxy IP address ipv4/ipv6. Not allowed to use:
|
port |
String |
true |
Port of proxy |
login |
String |
false |
Login for proxy which requires authorizaiton (basic) |
password |
String |
false |
Proxy password |
agent |
String |
true |
Browser's User-Agent which is used in emulation. It is required that you use a signature of a modern browser, otherwise Google will ask you to "update your browser" |
cookies |
String |
false |
Additional cookies which we must use during interaction with target page or Google. Format: 'cookie1=value1; cookie2=value2' |
Note: opts
can by another instance of Proxy. Constructor will copy all parametrs.
proxy.set(opts, [reset])
The way to change the proxy settings.
opts
- like constructor's opts
.
reset
- if false
- then opts overwrite the previous parameters. Otherwise - previous ones will be erased and new ones will be recorded. (Default: false
)
proxy.get()
Returns proxy parametrs.
let proxy = type: 'http' address: '8.8.8.8' port: '8080' login: 'user' password: 'pass' agent: 'Mozilla/5.0 ...' cookies: 'cookie1=value1; cookie2=value2'; console;/*{ type: 'http', address: '8.8.8.8', port: '8080', login: 'user', password: 'pass', agent: 'Mozilla/5.0 ...', cookies: 'cookie1=value1; cookie2=value2'}*/
proxy.toJSON([check])
Returns JSON-object. If check = true
check required proxy settings (Default: false
).
let proxy = type: 'http' address: '8.8.8.8' port: '8080' login: 'user' password: 'pass' agent: 'Mozilla/5.0 ...' cookies: 'cookie1=value1; cookie2=value2'; console;/*{ proxyType: 'http', proxyAddress: '8.8.8.8', proxyPort: '8080', proxyLogin: 'user', proxyPassword: 'pass', userAgent: 'Mozilla/5.0 ...', cookies: 'cookie1=value1; cookie2=value2'}*/
Proxy.checkProxy(proxyData)
Static method of the class Proxy
for checking the required fields of the proxy. If some required field is not specified, it will throw the error. Will return true
if all is good.
let proxy = type: 'socks4' address: '8.8.8.8' port: '8080'; Proxy;// Same asProxy;// Same asProxy; // All above throw Error('No agent');
Tasks
For quick and easy use of api, use list of classes that implement all supported task types:
ImageToTextTask
- Classic image to text captchaNoCaptchaTask
- Google's reCAPTCHA v2 (I'm not a robot).GeeTestTask
- GeeTestFunCaptchaTask
- FunCaptchaSquareNetTextTask
- Something like Google's pazzle (find bus on pictures), but too oldCustomCaptchaTask
- Custom tasks. [TODO: more text]
const Anticaptcha = ; const ImageToTextTask = AnticaptchaImageToTextTask;const NoCaptchaTask = AnticaptchaNoCaptchaTask;// etc ...
new <Task>(opts, [proxy])
Create new task (type of task is determined by the class name) with opts
and proxy
(if it's type of task support proxy mod).
<task>.type
Property that returns the task type. Note: you can not set type of task, it is determines automaticaly.
<task>.data
Getter/Setter that helps to get/set task opts.
<task>.proxy
Getter/Setter that helps to get/set proxy of the task. It's can be or Boolean
(true
/false
) or Proxy
instance ot proxy-object. If setted true
, the proxy params before sending the request will be taken from the default proxy data from Anticaptcha
instance.
Note: if task supports proxy-mod, then type will automatically switched.
<task>.toJSON()
Serialization task opts for API request.
Result of task
[TODO: add text]
new ImageToTextTask(opts)
Classic task convert text from image to textbox.
Params (otps
):
Field | Type | Required | Default | Description |
---|---|---|---|---|
body |
String |
yes |
- | File body encoded in base64. Make sure to send it without line breaks. |
phrase |
Boolean |
no |
false |
false - no requirements true - worker must enter an answer with at least one "space" |
case |
Boolean |
no |
false |
false - no requirements true - worker will see a special mark telling that answer must be entered with case sensitivity |
numeric |
Integer |
no |
0 |
0 - no requirements 1 - only number are allowed 2 - any letters are allowed except numbers |
math |
Boolean |
no |
false |
false - no requirements true - worker will see a special mark telling that answer must be calculated |
length |
Array<Integer> |
no |
[0,0] |
Set min and max length of an answer. First element - min, second - max. 0 - no requirements >1 - defines min/max length of the answer |
comment |
String |
no |
'' |
Additional comment for workers like "enter letters in red color" |
Result:
text: "the answer" url: "http://webaddress.com/captcha.jpg"
new NoCaptchaTask(opts, [proxy])
Google's reCAPTCHA v2 (I'm not a robot). Note: supports proxy mod.
Params (otps
):
Field | Type | Required | Description |
---|---|---|---|
url |
String |
yes |
Address of target web page |
sitekey |
String |
yes |
Recaptcha website key <div class="g-recaptcha" data-sitekey="THAT_ONE"></div> |
stoken |
String |
no |
Deprecated |
isVisible |
Boolean |
no |
Specify if Recaptcha is invisible |
Result:
gRecaptchaResponse: "3AHJ_VuvYIBNBW5yyv0zRYJ75VkOKvhKj9_xGBJKnQimF72rfoq3Iy-DyGHMwLAo6a3"
Field | Type | Description |
---|---|---|
gRecaptchaResponse |
String |
Hash string which is required for interacting with submit form on target website. It looks like this: <textarea id="g-recaptcha-response" ..></textarea> |
new GeeTestTask(opts, [proxy])
GeeTest captcha. Note: supports proxy mod.
Params (otps
):
Field | Type | Required | Description |
---|---|---|---|
url |
String |
yes |
Address of target web page |
gt |
String |
yes |
The domain key |
challenge |
String |
yes |
Changing token key. Make sure to grab fresh one for each captcha, otherwise you will be charged for error task. |
Result:
challenge: "3c1c5153aa48011e92883aed820069f3hj" validate: "47ad5a0a6eb98a95b2bcd9e9eecc8272" seccode: "83fa4f2d23005fc91c3a015a1613f803|jordan"
Field | Type | Description |
---|---|---|
challenge |
String |
Hash string which is required for interacting with submit form on target website |
validate |
String |
Hash string which is required too |
seccode |
String |
Another required hash string, we have no idea why there are 3 of them |
new FunCaptchaTask(opts, [proxy])
FunCaptcha Note: supports proxy mod.
Params (otps
):
Field | Type | Required | Description |
---|---|---|---|
url |
String |
yes |
Address of target web page |
publickey |
String |
yes |
Funcaptcha public key <div id="funcaptcha" data-pkey="THIS_ONE"></div> |
Result:
token: "36859d1086acb06e7.08293101|r=ap-southeast-1|metabgclr=%23ffffff|guitextcolor=%23555555|metaiconclr=%23cccccc|meta=3|pk=3B24C079-2DF1-771D-913A-11F824CD5A7C|injs=https://cdn.funcaptcha.com/fc/assets/graphics/etoxic/url_force.js|rid=11|cdn_url=https://cdn.funcaptcha.com/fc|surl=https://funcaptcha.com"
Field | Type | Description |
---|---|---|
token |
String |
Hash string which is required for interacting with submit form on target website. |
new SquareNetTextTask(opts)
This type of tasks takes your image, adds custom grid on it and asks our worker to mark specified objects on it. Something like Google's pazzle (find car on pictures), but too old.
Params (otps
):
Field | Type | Required | Description |
---|---|---|---|
body |
String |
yes |
File body encoded in base64. Make sure to send it without line breaks |
name |
String |
yes |
Name of the object. Example: banana |
Result:
cellNumbers: 467
Field | Type | Description |
---|---|---|
cellNumbers |
Array<Integer> |
Array holding cell numbers which start from 0, left to right, top to the bottom. |
new CustomCaptchaTask(opts)
This type of tasks is suitable for use when you need to describe what is on an image and you need workers to fill a custom form for this.
Examples:
- Read letters and numbers from a car license plate
- Find a phone number on a commercial
- Complete task like "count monkeys on a picture"
- etc.
Params (otps
):
Field | Type | Required | Description |
---|---|---|---|
url |
String |
yes |
Address of an image |
assignment |
String |
no |
Describe what worker must do in English |
forms |
form/Object |
no |
Custom form object. It can be or JSON-object or instance of Form To build this object you have 3 options:
|
Result:
taskId: 407533072 imageUrl: "https://files.anti-captcha.com/26/41f/c23/7c50ff19.jpg" assignment: "Enter license plate number" status: "complete" answers: license_plate: "TONFNTI" color: "grey"
[TODO: add text]
Form
Form
is created to create forms for CustomCaptchaTask
. It has next fields:
TextField
- simple plain text.LinkField
- button-link (HTML-tag:<a>
).ImageField
- static image (HTML-tag:<img>
).TextboxField
- textbox (HTML-tag:<input type="text"></input>
).TextareaField
- textarea (HTML-tag:<textarea></textarea>
).CheckboxField
- checkbox (HTML-tag:<input type="checkbox"></input>
).RadioField
- list of radio inputs (HTML-tag:<input type="radio"></input>...
).SelectField
- select (HTML-tag:<select><option>One</option>...</select>
).ImageUploadField
- file uploader (HTML-tag:<input type="file"></input>
).
const Form = AnticaptchaForm; // Creating formlet form = ;form;form;form; // Creating tasklet customTask = url: 'http://url_to_the_image.com' assigment: 'Please answer on questions' form: form; // Sending taskanticaptcha;
[TODO: add image example]
new Form()
[TODO: add text]
form.add(field)
Add new field to form. field
- instance of any Field
. Returns id
of the added field.
form.remove(id)
Remove field from form. id
- id of the previous added field. Returns true
if field finded and removed, false
- otherwise.
form.toJSON()
Stringify form
to JSON object according to documentation.
Fields
Some points:
- For all
Field
s first argument islabel
- description for the form field or content. Its type isString
orArray<String>
with two elements. If you passedArray
then first element will be label, second - subtitle for label. Example:new TextField('Label')
andnew TextField(['Label', 'Subtitle'])
- For all dynamic fields (
TextboxField
,CheckboxField
, etc.) second arguments isname
- like<input>
attributename
. It's used to get values ofCustomCaptchaTask
's answers . Note: It's must be unique!
new TextField(label, text)
Plain text. It's static field. Compiled into:
Field | Type | Required | Description |
---|---|---|---|
text |
String |
yes |
Set text |
new LinkField(label, url, text)
A link button. It's static field. Compiled into:
{text}
Field | Type | Required | Description |
---|---|---|---|
url |
String |
yes |
Sets link's url |
text |
String |
yes |
Sets a body to link |
new ImageField(label, url)
Image field displays an image with zoom function. It's static field. Compiled into:
Field | Type | Required | Description |
---|---|---|---|
url |
String |
yes |
Sets source url of the image |
new TextboxField(label, name, [opts])
Single-line text input - textbox
. It's dynamic field.
Compiled into:
Field | Type | Required | Description |
---|---|---|---|
opts.placeholder |
String |
no |
Sets input 's placeholder |
opts.width |
Integer |
no |
Sets width of the input in percents. One number from 25 , 33 , 50 or 100 |
new TextareaField(label, name, [opts])
Multi-line text input - textarea
. It's dynamic field.
Compiled into:
Field | Type | Required | Description |
---|---|---|---|
opts.placeholder |
String |
no |
Sets input 's placeholder |
opts.width |
Integer |
no |
Sets width of the input in percents. One number from 25 , 33 , 50 or 100 |
opts.rows |
Integer |
no |
Sets number for lines |
new CheckboxField(label, name, text)
Checkbox, single option input. It's dynamic field. Compiled into:
{text}
Field | Type | Required | Description |
---|---|---|---|
text |
String |
yes |
Text label for checkbox |
new RadioField(label, name, keyvals)
Set of radio buttons. It's dynamic field.
Example: keyvals = {key1: "val1", key2: "val2", key3: "val3"}
compiles into:
val1val2val3
Field | Type | Required | Description |
---|---|---|---|
keyvals |
Object |
yes |
Object with key-values. Each object key is a value , each keyvals value is a content of input. |
new SelectField(label, name, keyvals)
Dropdown select box. It's dynamic field.
Example: keyvals = {key1: "val1", key2: "val2", key3: "val3"}
compiles into:
val1 val2 val3
Field | Type | Required | Description |
---|---|---|---|
keyvals |
Object |
yes |
Object with key-values. Each object key is a value , each keyvals value is a content of option. |
new ImageUploadField(label, name)
Image upload input. It's dynamic field.
ApiError
To catch all API errors use Bluebird's filtered catch.
const Anticaptcha = ; ... anticaptcha ;