Skip to content

Commit 7880a84

Browse files
committed
Add TSPD captcha support with tests and examples
1 parent f596f77 commit 7880a84

10 files changed

Lines changed: 287 additions & 1 deletion

File tree

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Examples of API requests for different captcha types are available on the [Pytho
5353
- [Yidun](#yidun)
5454
- [Hunt](#hunt)
5555
- [Alibaba](#alibaba)
56+
- [TSPD](#tspd)
5657
- [Other methods](#other-methods)
5758
- [send / get\_result](#send--get_result)
5859
- [balance](#balance)
@@ -585,6 +586,19 @@ result = solver.alibaba(pageurl='https://www.example.com',
585586
)
586587
```
587588

589+
### TSPD
590+
591+
<sup>[API method description.](https://2captcha.com/2captcha-api#tspd)</sup>
592+
593+
Use this method to solve TSPD captcha. Returns a JSON string with cookies.
594+
```python
595+
result = solver.tspd(pageurl='https://example.com/login',
596+
tspd_cookie='TS386a400d029=082670...010245; TS386a400d078=082670...dbb3b0c',
597+
html_page_base64='PCFET0NUWVBFIGh0bWw+...',
598+
proxy={'type': 'HTTP', 'uri': 'login:password@IP_address:PORT'},
599+
)
600+
```
601+
588602
## Other methods
589603

590604
### send / get_result

examples/async/async_tspd.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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.tspd(
22+
pageurl='https://example.com/login',
23+
tspd_cookie='TS386a400d029=082670...010245; TS386a400d078=082670...dbb3b0c',
24+
html_page_base64='PCFET0NUWVBFIGh0bWw+...',
25+
proxy={'type': 'HTTP', 'uri': 'login:password@IP_address:PORT'},
26+
)
27+
28+
except Exception as e:
29+
sys.exit(e)
30+
31+
if __name__ == '__main__':
32+
result = asyncio.run(solve_captcha())
33+
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.tspd(
31+
pageurl='https://example.com/login',
32+
tspd_cookie='TS386a400d029=082670...010245; TS386a400d078=082670...dbb3b0c',
33+
html_page_base64='PCFET0NUWVBFIGh0bWw+...',
34+
proxy={'type': 'HTTP', 'uri': 'login:password@IP_address:PORT'},
35+
useragent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36',
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/tspd.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+
solver = TwoCaptcha(api_key)
17+
18+
try:
19+
result = solver.tspd(
20+
pageurl='https://example.com/login',
21+
tspd_cookie='TS386a400d029=082670...010245; TS386a400d078=082670...dbb3b0c',
22+
html_page_base64='PCFET0NUWVBFIGh0bWw+...',
23+
proxy={'type': 'HTTP', 'uri': 'login:password@IP_address:PORT'},
24+
)
25+
26+
except Exception as e:
27+
sys.exit(e)
28+
29+
else:
30+
sys.exit('result: ' + str(result))

examples/sync/tspd_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.tspd(
29+
pageurl='https://example.com/login',
30+
tspd_cookie='TS386a400d029=082670...010245; TS386a400d078=082670...dbb3b0c',
31+
html_page_base64='PCFET0NUWVBFIGh0bWw+...',
32+
proxy={'type': 'HTTP', 'uri': 'login:password@IP_address:PORT'},
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+
)
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'],
39+
'Capy Puzzle', 'MTCaptcha', 'Friendly Captcha', 'Tencent', 'Cutcaptcha', 'DataDome', 'VK Captcha', 'CaptchaFox', 'Prosopo', 'cybersiara', 'Hunt', 'Alibaba', 'TSPD'],
4040
python_requires='>=3.8',
4141
test_suite='tests')

tests/async/test_async_tspd.py

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

tests/sync/test_tspd.py

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

twocaptcha/async_solver.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,32 @@ async def alibaba(self, pageurl, scene_id, prefix, **kwargs):
11391139

11401140
return await result
11411141

1142+
async def tspd(self, pageurl, tspd_cookie, html_page_base64, proxy, **kwargs):
1143+
'''Wrapper for solving TSPD captcha.
1144+
1145+
Parameters
1146+
__________
1147+
pageurl : str
1148+
Full URL of the page with the captcha.
1149+
tspd_cookie : str
1150+
Cookies received on the TSPD challenge page.
1151+
html_page_base64 : str
1152+
Full HTML of the challenge page, Base64 encoded.
1153+
proxy : dict
1154+
{'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
1155+
useragent : str, optional
1156+
Browser User-Agent. We recommend sending a valid Windows browser string.
1157+
'''
1158+
result = self.solve(
1159+
method="tspd",
1160+
pageurl=pageurl,
1161+
tspd_cookie=tspd_cookie,
1162+
html_page_base64=html_page_base64,
1163+
proxy=proxy,
1164+
**kwargs)
1165+
1166+
return await result
1167+
11421168
async def solve(self, timeout=0, polling_interval=0, **kwargs):
11431169
'''Sends captcha, receives result.
11441170

twocaptcha/solver.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ class TwoCaptcha():
117117
Wrapper for solving Hunt captcha.
118118
alibaba(self, pageurl, scene_id, prefix, **kwargs)
119119
Wrapper for solving Alibaba captcha.
120+
tspd(self, pageurl, tspd_cookie, html_page_base64, proxy, **kwargs)
121+
Wrapper for solving TSPD captcha.
120122
solve(timeout=0, polling_interval=0, **kwargs)
121123
Sends CAPTCHA data and retrieves the result.
122124
balance()
@@ -1285,6 +1287,32 @@ def alibaba(self, pageurl, scene_id, prefix, **kwargs):
12851287

12861288
return result
12871289

1290+
def tspd(self, pageurl, tspd_cookie, html_page_base64, proxy, **kwargs):
1291+
'''Wrapper for solving TSPD captcha.
1292+
1293+
Parameters
1294+
__________
1295+
pageurl : str
1296+
Full URL of the page with the captcha.
1297+
tspd_cookie : str
1298+
Cookies received on the TSPD challenge page.
1299+
html_page_base64 : str
1300+
Full HTML of the challenge page, Base64 encoded.
1301+
proxy : dict
1302+
{'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
1303+
useragent : str, optional
1304+
Browser User-Agent. We recommend sending a valid Windows browser string.
1305+
'''
1306+
result = self.solve(
1307+
method="tspd",
1308+
pageurl=pageurl,
1309+
tspd_cookie=tspd_cookie,
1310+
html_page_base64=html_page_base64,
1311+
proxy=proxy,
1312+
**kwargs)
1313+
1314+
return result
1315+
12881316

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

0 commit comments

Comments
 (0)