Skip to content

Commit 46067e2

Browse files
authored
Adding methods mtcaptcha, friendly captcha, cutcaptcha (#73)
* Adding methods mtcaptcha, friendly captcha, cutcaptcha to solver.py Adding examples mtchaptcha.py, mtcaptcha_options.py, friendly_captcha.py, friendly_captcha_options.py, cutcaptcha.py, cutcaptcha_options.py to examples folder Adding tests test_mtcaptcha.py, test_friendly_captcha.py, test_cutcaptcha.py to tests folder Signed-off-by: Maxim S <[email protected]> * - Fixed parameter {'method': 'cutcaptcha'} in the "send" parameters of the send request in the file test_cutcaptcha.py - Adding .idea/, .DS_Store to .gitignore Signed-off-by: Maxim S <[email protected]> --------- Signed-off-by: Maxim S <[email protected]>
1 parent 67690fc commit 46067e2

12 files changed

+391
-1
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,6 @@ dmypy.json
137137
# Cython debug symbols
138138
cython_debug/
139139

140-
.vscode/
140+
.vscode/
141+
.idea/
142+
.DS_Store

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ The easiest way to quickly integrate [2Captcha] captcha solving service into you
2525
- [Canvas](#canvas)
2626
- [ClickCaptcha](#clickcaptcha)
2727
- [Rotate](#rotate)
28+
- [MTCaptcha](#mtcaptcha)
29+
- [Friendly Captcha](#friendly_captcha)
30+
- [Cutcaptcha](#cutcaptcha)
2831
- [Other methods](#other-methods)
2932
- [send / getResult](#send--getresult)
3033
- [balance](#balance)
@@ -253,6 +256,32 @@ This method can be used to solve a captcha that asks to rotate an object. Mostly
253256
result = solver.rotate('path/to/captcha.jpg', param1=..., ...)
254257
```
255258

259+
### MTCaptcha
260+
Use this method to solve MTCaptcha and obtain a token to bypass the protection.
261+
```python
262+
result = solver.mtcaptcha(sitekey='MTPublic-KzqLY1cKH',
263+
url='https://2captcha.com/demo/mtcaptcha',
264+
param1=..., ...)
265+
```
266+
267+
### Friendly Captcha
268+
Friendly Captcha solving method. Returns a token.
269+
```python
270+
result = solver.friendly_captcha(sitekey='FCMGEMUD2KTDSQ5H',
271+
url='https://friendlycaptcha.com/demo',
272+
param1=..., ...)
273+
```
274+
275+
### Cutcaptcha
276+
Use this method to solve Cutcaptcha. Returns the response in JSON.
277+
```python
278+
result = solver.cutcaptcha(misery_key='ad52c87af17e2ec09b8d918c9f00416b1cb8c320',
279+
apikey='SAs61IAI',
280+
url='https://mysite.com/page/with/cutcaptcha',
281+
param1=..., ...)
282+
```
283+
284+
256285
## Other methods
257286

258287
### send / getResult

examples/cutcaptcha.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import sys
2+
import os
3+
4+
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
5+
6+
from twocaptcha import TwoCaptcha
7+
8+
# in this example we store the API key inside environment variables that can be set like:
9+
# export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10+
# set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11+
# you can just set the API key directly to it's value like:
12+
# api_key="1abc234de56fab7c89012d34e56fa7b8"
13+
14+
api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
15+
16+
17+
solver = TwoCaptcha(api_key)
18+
19+
try:
20+
result = solver.cutcaptcha(
21+
misery_key='ad52c87af17e2ec09b8d918c9f00416b1cb8c320',
22+
apikey='SAs61IAI',
23+
url='https://mysite.com/page/with/cutcaptcha',
24+
)
25+
26+
except Exception as e:
27+
sys.exit(e)
28+
29+
else:
30+
sys.exit('result: ' + str(result))

examples/cutcaptcha_options.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import sys
2+
import os
3+
4+
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
5+
6+
from twocaptcha import TwoCaptcha
7+
8+
# in this example we store the API key inside environment variables that can be set like:
9+
# export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10+
# set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11+
# you can just set the API key directly to it's value like:
12+
# api_key="1abc234de56fab7c89012d34e56fa7b8"
13+
14+
api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
15+
16+
config = {
17+
'server': '2captcha.com', # can be also set to 'rucaptcha.com'
18+
'apiKey': api_key,
19+
'softId': 123,
20+
# 'callback': 'https://your.site/result-receiver', # if set, sovler with just return captchaId, not polling API for the answer
21+
'defaultTimeout': 120,
22+
'recaptchaTimeout': 600,
23+
'pollingInterval': 10,
24+
}
25+
26+
solver = TwoCaptcha(**config)
27+
28+
try:
29+
result = solver.cutcaptcha(misery_key='ad52c87af17e2ec09b8d918c9f00416b1cb8c320',
30+
apikey='SAs61IAI',
31+
url='https://mysite.com/page/with/cutcaptcha'
32+
# proxy={
33+
# 'type': 'HTTPS',
34+
# 'uri': 'login:password@IP_address:PORT'
35+
# }
36+
)
37+
38+
except Exception as e:
39+
sys.exit(e)
40+
41+
else:
42+
sys.exit('result: ' + str(result))

examples/friendly_captcha.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import sys
2+
import os
3+
4+
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
5+
6+
from twocaptcha import TwoCaptcha
7+
8+
# in this example we store the API key inside environment variables that can be set like:
9+
# export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10+
# set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11+
# you can just set the API key directly to it's value like:
12+
# api_key="1abc234de56fab7c89012d34e56fa7b8"
13+
14+
api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
15+
16+
solver = TwoCaptcha(api_key)
17+
18+
try:
19+
result = solver.friendly_captcha(
20+
sitekey='FCMGEMUD2KTDSQ5H',
21+
url='https://friendlycaptcha.com/demo',
22+
)
23+
24+
except Exception as e:
25+
sys.exit(e)
26+
27+
else:
28+
sys.exit('result: ' + str(result))

examples/friendly_captcha_options.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import sys
2+
import os
3+
4+
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
5+
6+
from twocaptcha import TwoCaptcha
7+
8+
# in this example we store the API key inside environment variables that can be set like:
9+
# export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10+
# set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11+
# you can just set the API key directly to it's value like:
12+
# api_key="1abc234de56fab7c89012d34e56fa7b8"
13+
14+
api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
15+
16+
config = {
17+
'server': '2captcha.com', # can be also set to 'rucaptcha.com'
18+
'apiKey': api_key,
19+
'softId': 123,
20+
# 'callback': 'https://your.site/result-receiver', # if set, sovler with just return captchaId, not polling API for the answer
21+
'defaultTimeout': 120,
22+
'recaptchaTimeout': 600,
23+
'pollingInterval': 10,
24+
}
25+
26+
solver = TwoCaptcha(**config)
27+
28+
try:
29+
result = solver.friendly_captcha(sitekey='FCMGEMUD2KTDSQ5H',
30+
url='https://friendlycaptcha.com/demo',
31+
# proxy={
32+
# 'type': 'HTTPS',
33+
# 'uri': 'login:password@IP_address:PORT'
34+
# }
35+
)
36+
37+
except Exception as e:
38+
sys.exit(e)
39+
40+
else:
41+
sys.exit('result: ' + str(result))

examples/mtcaptcha.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import sys
2+
import os
3+
4+
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
5+
6+
from twocaptcha import TwoCaptcha
7+
8+
# in this example we store the API key inside environment variables that can be set like:
9+
# export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10+
# set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11+
# you can just set the API key directly to it's value like:
12+
# api_key="1abc234de56fab7c89012d34e56fa7b8"
13+
14+
api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
15+
16+
solver = TwoCaptcha(api_key)
17+
18+
try:
19+
result = solver.mtcaptcha(
20+
sitekey='MTPublic-KzqLY1cKH',
21+
url='https://2captcha.com/demo/mtcaptcha',
22+
)
23+
24+
except Exception as e:
25+
sys.exit(e)
26+
27+
else:
28+
sys.exit('result: ' + str(result))

examples/mtcaptcha_options.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import sys
2+
import os
3+
4+
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
5+
6+
from twocaptcha import TwoCaptcha
7+
8+
# in this example we store the API key inside environment variables that can be set like:
9+
# export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10+
# set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11+
# you can just set the API key directly to it's value like:
12+
# api_key="1abc234de56fab7c89012d34e56fa7b8"
13+
14+
api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
15+
16+
config = {
17+
'server': '2captcha.com', # can be also set to 'rucaptcha.com'
18+
'apiKey': api_key,
19+
'softId': 123,
20+
# 'callback': 'https://your.site/result-receiver', # if set, sovler with just return captchaId, not polling API for the answer
21+
'defaultTimeout': 120,
22+
'recaptchaTimeout': 600,
23+
'pollingInterval': 10,
24+
}
25+
26+
solver = TwoCaptcha(**config)
27+
28+
try:
29+
result = solver.mtcaptcha(sitekey='MTPublic-KzqLY1cKH',
30+
url='https://2captcha.com/demo/mtcaptcha',
31+
# proxy={
32+
# 'type': 'HTTPS',
33+
# 'uri': 'login:password@IP_address:PORT'
34+
# }
35+
)
36+
37+
except Exception as e:
38+
sys.exit(e)
39+
40+
else:
41+
sys.exit('result: ' + str(result))

tests/test_cutcaptcha.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env python3
2+
3+
import unittest
4+
5+
try:
6+
from .abstract import AbstractTest
7+
except ImportError:
8+
from abstract import AbstractTest
9+
10+
11+
class CutcaptchaTest(AbstractTest):
12+
13+
def test_all_params(self):
14+
params = {
15+
'misery_key': 'ad52c87af17e2ec09b8d918c9f00416b1cb8c320',
16+
'apikey': 'SAs61IAI',
17+
'url': 'https://www.site.com/page/',
18+
}
19+
20+
sends = {
21+
'method': 'cutcaptcha',
22+
'api_key': 'SAs61IAI',
23+
'misery_key': 'ad52c87af17e2ec09b8d918c9f00416b1cb8c320',
24+
'pageurl': 'https://www.site.com/page/',
25+
}
26+
27+
return self.send_return(sends, self.solver.cutcaptcha, **params)
28+
29+
30+
if __name__ == '__main__':
31+
unittest.main()

tests/test_friendly_captcha.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env python3
2+
3+
import unittest
4+
5+
try:
6+
from .abstract import AbstractTest
7+
except ImportError:
8+
from abstract import AbstractTest
9+
10+
11+
class FriendlyCaptchaTest(AbstractTest):
12+
13+
def test_all_params(self):
14+
params = {
15+
'sitekey': 'FCMGEMUD2KTDSQ5H',
16+
'url': 'https://friendlycaptcha.com/demo',
17+
}
18+
19+
sends = {
20+
'method': 'friendly_captcha',
21+
'sitekey': 'FCMGEMUD2KTDSQ5H',
22+
'pageurl': 'https://friendlycaptcha.com/demo',
23+
}
24+
25+
return self.send_return(sends, self.solver.friendly_captcha, **params)
26+
27+
28+
if __name__ == '__main__':
29+
unittest.main()

tests/test_mtcaptcha.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env python3
2+
3+
import unittest
4+
5+
try:
6+
from .abstract import AbstractTest
7+
except ImportError:
8+
from abstract import AbstractTest
9+
10+
11+
class MTCaptchaTest(AbstractTest):
12+
13+
def test_all_params(self):
14+
params = {
15+
'sitekey': 'MTPublic-KzqLY1cKH',
16+
'url': 'https://2captcha.com/demo/mtcaptcha',
17+
}
18+
19+
sends = {
20+
'method': 'mt_captcha',
21+
'sitekey': 'MTPublic-KzqLY1cKH',
22+
'pageurl': 'https://2captcha.com/demo/mtcaptcha',
23+
}
24+
25+
return self.send_return(sends, self.solver.mtcaptcha, **params)
26+
27+
28+
if __name__ == '__main__':
29+
unittest.main()

0 commit comments

Comments
 (0)