Skip to content

Commit 6c8626d

Browse files
Add Cutcaptcha method
1 parent db71eff commit 6c8626d

5 files changed

Lines changed: 94 additions & 26 deletions

File tree

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Examples of API requests for different captcha types are available on the [JavaS
4040
- [Canvas](#canvas)
4141
- [Rotate](#rotate)
4242
- [KeyCaptcha](#keycaptcha)
43+
- [Cutcaptcha](#cutcaptcha)
4344
- [Other methods](#other-methods)
4445
- [goodReport](#goodreport)
4546
- [badReport](#badreport)
@@ -576,6 +577,26 @@ solver.keyCaptcha({
576577
webServerSign: '02f7f9669f1269595c4c69bcd4a3c52e',
577578
webServerSign2: 'd888700f6f324ec0f32b44c32c50bde1'
578579
})
580+
.then((res) => {
581+
console.log(res);
582+
})
583+
.catch((err) => {
584+
console.log(err);
585+
})
586+
```
587+
588+
### Cutcaptcha
589+
590+
<sup>[API method description.](https://2captcha.com/2captcha-api#cutcaptcha)</sup>
591+
592+
Use this method to solve Cutcaptcha. Returns the response in JSON.
593+
594+
```js
595+
solver.cutCaptcha({
596+
pageurl: "https://mysite.com/page/with/cutcaptcha",
597+
misery_key: "098e6a849af406142e3150dbf4e6d0538db2b51f",
598+
api_key: "SAs61IAI",
599+
})
579600
.then((res) => {
580601
console.log(res);
581602
})

examples/cutcaptcha.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const TwoCaptcha = require("../dist/index.js");
2+
require('dotenv').config();
3+
const APIKEY = process.env.APIKEY
4+
const solver = new TwoCaptcha.Solver(APIKEY);
5+
6+
solver.cutCaptcha({
7+
pageurl: "https://mysite.com/page/with/cutcaptcha",
8+
miseryKey: "098e6a849af406142e3150dbf4e6d0538db2b51f",
9+
apiKey: "SAs61IAI",
10+
})
11+
.then((res) => {
12+
console.log(res);
13+
})
14+
.catch((err) => {
15+
console.log(err);
16+
})

src/structs/2captcha.ts

Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,15 @@ export interface paramsMTCaptcha {
208208
proxytype?: string,
209209
}
210210

211+
export interface paramsCutcaptcha {
212+
pageurl: string,
213+
miseryKey: string,
214+
apiKey: string,
215+
pingback?: string,
216+
proxy?: string,
217+
proxytype?: string
218+
}
219+
211220
export interface friendlyCaptcha {
212221
pageurl: string,
213222
sitekey: string,
@@ -1234,37 +1243,51 @@ public async mtCaptcha(params: paramsMTCaptcha): Promise<CaptchaAnswer> {
12341243
}
12351244

12361245
/**
1237-
* ### Solves Cutcaptcha
1238-
*
1239-
* @param {{ pageurl, sitekey, userAgent, pingback, proxy, proxytype}} params Parameters MTCaptcha as an object.
1240-
* @param {string} params.pageurl Full `URL` of the page where you see the captcha.
1241-
* @param {string} params.sitekey TThe value of `sitekey` parameter found on the page.
1242-
* @param {string} params.pingback URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on the server. [More info here](https://2captcha.com/2captcha-api#pingback).
1243-
* @param {string} params.proxy Format: `login:password@123.123.123.123:3128` You can find more info about proxies [here](https://2captcha.com/2captcha-api#proxies).
1244-
* @param {string} params.proxytype Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
1245-
*
1246-
* @example
1247-
* solver.cutCaptcha({
1248-
* pageurl: "https://service.mtcaptcha.com/mtcv1/demo/index.html",
1249-
* sitekey: "MTPublic-DemoKey9M"
1250-
* })
1251-
* .then((res) => {
1252-
* console.log(res);
1253-
* })
1254-
* .catch((err) => {
1255-
* console.log(err);
1256-
* })
1257-
*/
1258-
public async cutCaptcha(params: paramsMTCaptcha): Promise<CaptchaAnswer> {
1259-
checkCaptchaParams(params, "mt_captcha")
1246+
* ### Solves a Cutcaptcha.
1247+
*
1248+
* Use this method to solve Cutcaptcha. Returns the response in JSON.
1249+
* [Read more about Cutcaptcha](https://2captcha.com/2captcha-api#Cutcaptcha).
1250+
*
1251+
* @param {{ pageurl, miseryKey, apiKey, pingback, proxy, proxytype }} params Parameters for solving Cutcaptcha as an object.
1252+
* @param {string} params.pageurl The URL where the captcha is located.
1253+
* @param {string} params.miseryKey The value of `CUTCAPTCHA_MISERY_KEY` variable defined on page.
1254+
* @param {string} params.apiKey The value of `data-apikey` attribute of iframe's body. Also the name of javascript file included on the page
1255+
* @param {string} [params.pingback] Optional param. URL for pingback (callback) response when captcha is solved.
1256+
* @param {string} [params.proxy] Optional param. Proxy to use while solving the captcha. Format: `login:password@123.123.123.123:3128`.
1257+
* @param {string} [params.proxytype] Optional param. Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
1258+
*
1259+
* @returns {Promise<CaptchaAnswer>} The result from the solve.
1260+
* @throws APIError
1261+
*
1262+
* @example
1263+
* solver.cutCaptcha({
1264+
* pageurl: "https://mysite.com/page/with/cutcaptcha",
1265+
* miseryKey: "098e6a849af406142e3150dbf4e6d0538db2b51f",
1266+
* apiKey: "SAs61IAI",
1267+
* })
1268+
* .then((res) => {
1269+
* console.log(res);
1270+
* })
1271+
* .catch((err) => {
1272+
* console.log(err);
1273+
* })
1274+
*/
1275+
public async cutCaptcha(params: paramsCutcaptcha): Promise<CaptchaAnswer> {
1276+
params = renameParams(params)
1277+
checkCaptchaParams(params, "cutcaptcha")
12601278

12611279
const payload = {
12621280
...params,
1263-
method: "mt_captcha",
1281+
method: "cutcaptcha",
12641282
...this.defaultPayload,
12651283
}
12661284

1267-
const response = await fetch(this.in + utils.objectToURI(payload))
1285+
const URL = this.in
1286+
const response = await fetch(URL, {
1287+
body: JSON.stringify(payload),
1288+
method: "post",
1289+
headers: {'Content-Type': 'application/json'}
1290+
})
12681291
const result = await response.text()
12691292

12701293
let data;

src/utils/checkCaptchaParams.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Captcha methods for which parameter checking is available
22
const supportedMethods = ["userrecaptcha", "hcaptcha", "geetest", "geetest_v4","yandex","funcaptcha","lemin","amazon_waf",
3-
"turnstile", "base64", "capy","datadome", "cybersiara", "mt_captcha", "bounding_box", 'friendly_captcha', 'grid', 'textcaptcha', 'canvas', 'rotatecaptcha', 'keycaptcha']
3+
"turnstile", "base64", "capy","datadome", "cybersiara", "mt_captcha", "bounding_box", 'friendly_captcha', 'grid', 'textcaptcha', 'canvas', 'rotatecaptcha', 'keycaptcha', 'cutcaptcha']
44

55
// Names of required fields that must be contained in the parameters captcha
66
const recaptchaRequiredFields = ['pageurl','googlekey']
@@ -25,6 +25,7 @@ const textCaptchaRequiredFields = ['textcaptcha']
2525
const canvasRequiredFields = ['body'] // and textinstructions or imginstructions
2626
const rotateRequiredFields = ['body']
2727
const keycaptchaRequiredFields = ['pageurl', 's_s_c_user_id', 's_s_c_session_id', 's_s_c_web_server_sign', 's_s_c_web_server_sign2']
28+
const cutcaptchaRequiredFields = ['pageurl', 'misery_key', 'api_key']
2829

2930
/**
3031
* Getting required arguments for a captcha.
@@ -99,6 +100,9 @@ const getRequiredFildsArr = (method: string):Array<string> => {
99100
case "keycaptcha":
100101
requiredFieldsArr = keycaptchaRequiredFields
101102
break;
103+
case "cutcaptcha":
104+
requiredFieldsArr = cutcaptchaRequiredFields
105+
break;
102106
}
103107
return requiredFieldsArr
104108
}

src/utils/renameParams.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ export default function renameParams(params: any) {
2929
"sessionId":"s_s_c_session_id",
3030
"webServerSign":"s_s_c_web_server_sign",
3131
"webServerSign2":"s_s_c_web_server_sign2",
32+
33+
// Cutcaptcha
34+
"miseryKey":"misery_key",
35+
"apiKey":"api_key",
3236
}
3337

3438
for(let key in params) {

0 commit comments

Comments
 (0)