Skip to content

Commit 4889a70

Browse files
authored
Add Basilisk captcha support with tests and examples (#145)
1 parent d41a12a commit 4889a70

10 files changed

Lines changed: 269 additions & 1 deletion

File tree

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ Examples of API requests for different captcha types are available on the [Pytho
5454
- [Hunt](#hunt)
5555
- [Alibaba](#alibaba)
5656
- [TSPD](#tspd)
57+
- [Basilisk](#basilisk)
5758
- [Other methods](#other-methods)
5859
- [send / get\_result](#send--get_result)
5960
- [balance](#balance)
@@ -599,6 +600,17 @@ result = solver.tspd(pageurl='https://example.com/login',
599600
)
600601
```
601602

603+
### Basilisk
604+
605+
<sup>[API method description.](https://2captcha.com/2captcha-api#basilisk)</sup>
606+
607+
Use this method to solve Basilisk captcha. Returns a token.
608+
```python
609+
result = solver.basilisk(pageurl='https://example.com/login',
610+
sitekey='b7890h...19fb2600897',
611+
)
612+
```
613+
602614
## Other methods
603615

604616
### send / get_result

examples/async/async_basilisk.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import asyncio
2+
import sys
3+
import os
4+
5+
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
6+
7+
from twocaptcha import AsyncTwoCaptcha
8+
9+
# in this example we store the API key inside environment variables that can be set like:
10+
# export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
11+
# set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
12+
# you can just set the API key directly to it's value like:
13+
# api_key="1abc234de56fab7c89012d34e56fa7b8"
14+
15+
api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
16+
17+
solver = AsyncTwoCaptcha(api_key)
18+
19+
async def solve_captcha():
20+
try:
21+
return await solver.basilisk(
22+
pageurl='https://example.com/login',
23+
sitekey='b7890h...19fb2600897',
24+
)
25+
26+
except Exception as e:
27+
sys.exit(e)
28+
29+
if __name__ == '__main__':
30+
result = asyncio.run(solve_captcha())
31+
sys.exit('result: ' + str(result))
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import asyncio
2+
import sys
3+
import os
4+
5+
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
6+
7+
from twocaptcha import AsyncTwoCaptcha
8+
9+
# in this example we store the API key inside environment variables that can be set like:
10+
# export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
11+
# set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
12+
# you can just set the API key directly to it's value like:
13+
# api_key="1abc234de56fab7c89012d34e56fa7b8"
14+
15+
api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
16+
17+
config = {
18+
'server': '2captcha.com', # can be also set to 'rucaptcha.com'
19+
'apiKey': api_key,
20+
'softId': 123,
21+
'defaultTimeout': 120,
22+
'recaptchaTimeout': 600,
23+
'pollingInterval': 10,
24+
}
25+
26+
solver = AsyncTwoCaptcha(**config)
27+
28+
async def solve_captcha():
29+
try:
30+
return await solver.basilisk(
31+
pageurl='https://example.com/login',
32+
sitekey='b7890h...19fb2600897',
33+
useragent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36',
34+
# proxy={'type': 'HTTP',
35+
# 'uri': 'login:password@IP_address:PORT'}
36+
)
37+
except Exception as e:
38+
sys.exit(e)
39+
40+
if __name__ == '__main__':
41+
result = asyncio.run(solve_captcha())
42+
sys.exit('result: ' + str(result))

examples/sync/basilisk.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.basilisk(
20+
pageurl='https://example.com/login',
21+
sitekey='b7890h...19fb2600897',
22+
)
23+
24+
except Exception as e:
25+
sys.exit(e)
26+
27+
else:
28+
sys.exit('result: ' + str(result))

examples/sync/basilisk_options.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
'defaultTimeout': 120,
21+
'recaptchaTimeout': 600,
22+
'pollingInterval': 10,
23+
}
24+
25+
solver = TwoCaptcha(**config)
26+
27+
try:
28+
result = solver.basilisk(
29+
pageurl='https://example.com/login',
30+
sitekey='b7890h...19fb2600897',
31+
useragent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36',
32+
# proxy={'type': 'HTTP',
33+
# 'uri': 'login:password@IP_address:PORT'}
34+
)
35+
36+
except Exception as e:
37+
sys.exit(e)
38+
39+
else:
40+
sys.exit('result: ' + str(result))

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ def get_version():
3636
'2captcha', 'captcha', 'api', 'captcha solver', 'reCAPTCHA',
3737
'FunCaptcha', 'Geetest', 'image captcha', 'Coordinates', 'Click Captcha',
3838
'Geetest V4', 'Lemin captcha', 'Amazon WAF', 'Cloudflare Turnstile',
39-
'Capy Puzzle', 'MTCaptcha', 'Friendly Captcha', 'Tencent', 'Cutcaptcha', 'DataDome', 'VK Captcha', 'CaptchaFox', 'Prosopo', 'cybersiara', 'Hunt', 'Alibaba', 'TSPD'],
39+
'Capy Puzzle', 'MTCaptcha', 'Friendly Captcha', 'Tencent', 'Cutcaptcha', 'DataDome', 'VK Captcha', 'CaptchaFox', 'Prosopo', 'cybersiara', 'Hunt', 'Alibaba', 'TSPD', 'Basilisk'],
4040
python_requires='>=3.8',
4141
test_suite='tests')

tests/async/test_async_basilisk.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env python3
2+
3+
import unittest
4+
5+
try:
6+
from .abstract_async import AsyncAbstractTest
7+
except ImportError:
8+
from abstract_async import AsyncAbstractTest
9+
10+
11+
class AsyncBasilisk(AsyncAbstractTest):
12+
def test_all_params(self):
13+
params = {
14+
'pageurl': 'https://example.com/login',
15+
'sitekey': 'b7890h...19fb2600897',
16+
'useragent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36',
17+
'proxy': {'type': 'HTTP',
18+
'uri': 'login:password@IP_address:PORT'}
19+
}
20+
21+
sends = {
22+
'method': 'basilisk',
23+
'pageurl': 'https://example.com/login',
24+
'sitekey': 'b7890h...19fb2600897',
25+
'useragent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36',
26+
'proxytype': 'HTTP',
27+
'proxy': 'login:password@IP_address:PORT'
28+
}
29+
30+
self.send_return(sends, self.solver.basilisk, **params)
31+
32+
33+
if __name__ == '__main__':
34+
unittest.main()

tests/sync/test_basilisk.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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 CaptchaBasilisk(AbstractTest):
12+
13+
def test_all_params(self):
14+
params = {
15+
'pageurl': 'https://example.com/login',
16+
'sitekey': 'b7890h...19fb2600897',
17+
'useragent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36',
18+
'proxy': {'type': 'HTTP',
19+
'uri': 'login:password@IP_address:PORT'}
20+
}
21+
22+
sends = {
23+
'method': 'basilisk',
24+
'pageurl': 'https://example.com/login',
25+
'sitekey': 'b7890h...19fb2600897',
26+
'useragent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36',
27+
'proxytype': 'HTTP',
28+
'proxy': 'login:password@IP_address:PORT'
29+
}
30+
31+
return self.send_return(sends, self.solver.basilisk, **params)
32+
33+
34+
if __name__ == '__main__':
35+
unittest.main()

twocaptcha/async_solver.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,6 +1165,28 @@ async def tspd(self, pageurl, tspd_cookie, html_page_base64, proxy, **kwargs):
11651165

11661166
return await result
11671167

1168+
async def basilisk(self, pageurl, sitekey, **kwargs):
1169+
'''Wrapper for solving Basilisk captcha.
1170+
1171+
Parameters
1172+
__________
1173+
pageurl : str
1174+
Full URL of the page with the captcha.
1175+
sitekey : str
1176+
The value of the data-site-key parameter found on the page.
1177+
useragent : str, optional
1178+
Browser User-Agent used to open the page.
1179+
proxy : dict, optional
1180+
{'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
1181+
'''
1182+
result = self.solve(
1183+
method="basilisk",
1184+
pageurl=pageurl,
1185+
sitekey=sitekey,
1186+
**kwargs)
1187+
1188+
return await result
1189+
11681190
async def solve(self, timeout=0, polling_interval=0, **kwargs):
11691191
'''Sends captcha, receives result.
11701192

twocaptcha/solver.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ class TwoCaptcha():
119119
Wrapper for solving Alibaba captcha.
120120
tspd(self, pageurl, tspd_cookie, html_page_base64, proxy, **kwargs)
121121
Wrapper for solving TSPD captcha.
122+
basilisk(self, pageurl, sitekey, **kwargs)
123+
Wrapper for solving Basilisk captcha.
122124
solve(timeout=0, polling_interval=0, **kwargs)
123125
Sends CAPTCHA data and retrieves the result.
124126
balance()
@@ -1313,6 +1315,28 @@ def tspd(self, pageurl, tspd_cookie, html_page_base64, proxy, **kwargs):
13131315

13141316
return result
13151317

1318+
def basilisk(self, pageurl, sitekey, **kwargs):
1319+
'''Wrapper for solving Basilisk captcha.
1320+
1321+
Parameters
1322+
__________
1323+
pageurl : str
1324+
Full URL of the page with the captcha.
1325+
sitekey : str
1326+
The value of the data-site-key parameter found on the page.
1327+
useragent : str, optional
1328+
Browser User-Agent used to open the page.
1329+
proxy : dict, optional
1330+
{'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
1331+
'''
1332+
result = self.solve(
1333+
method="basilisk",
1334+
pageurl=pageurl,
1335+
sitekey=sitekey,
1336+
**kwargs)
1337+
1338+
return result
1339+
13161340

13171341
def solve(self, timeout=0, polling_interval=0, **kwargs):
13181342
'''Sends captcha, receives result.

0 commit comments

Comments
 (0)