Skip to content

Commit dfed176

Browse files
committed
added vkcaptcha
1 parent d574c50 commit dfed176

File tree

6 files changed

+199
-6
lines changed

6 files changed

+199
-6
lines changed

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Examples of API requests for different captcha types are available on the [Pytho
4343
- [Tencent](#tencent)
4444
- [DataDome](#datadome)
4545
- [VKImage](#vkimage)
46+
- [VKCaptcha](#vkcaptcha)
4647
- [CyberSiARA](#cybersiara)
4748
- [Other methods](#other-methods)
4849
- [send / get\_result](#send--get_result)
@@ -440,16 +441,34 @@ result = solver.datadome(captcha_url="https://geo.captcha-delivery.com/captcha/?
440441
},
441442
param1=..., ...)
442443
```
444+
443445
### VKImage
444446

445447
<sup>[API method description.](https://2captcha.com/2captcha-api#vkcaptcha)</sup>
446448

447-
This method can be used to solve VK captcha using graphical captcha. Returns the number of steps and solution value in the target site's API format. Or get an extended response by passing the `extendedResponse=True` attribute to the class instance
449+
This method can be used to solve VK captcha using graphical captcha. Returns the number of steps and solution value in the target site's API format.
448450

449451
```python
450452
result = solver.vkimage('path/to/captcha.jpg', steps='[5,4,7,7,14,22,8,...]', ...)
451453
```
452454

455+
### VKCaptcha
456+
457+
<sup>[API method description.](https://2captcha.com/2captcha-api#vkcaptcha)</sup>
458+
459+
This method can be used to solve VK Captcha using a token.
460+
461+
> [!IMPORTANT]
462+
> To solve the VK Captcha, you must use a proxy. It is recommended to use [residential proxies].
463+
464+
```python
465+
result = solver.vkcaptcha(redirect_uri='https://id.vk.ru/...',
466+
userAgent='Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36..',
467+
proxy={
468+
'type': 'HTTP',
469+
'uri': 'login:password@IP_address:PORT'}
470+
)
471+
```
453472

454473
### CyberSiARA
455474

examples/captchafox.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/vkcaptcha.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import sys
2+
import os
3+
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
4+
5+
from twocaptcha import TwoCaptcha
6+
7+
# in this example we store the API key inside environment variables that can be set like:
8+
# export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
9+
# set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
10+
# you can just set the API key directly to it's value like:
11+
# api_key="1abc234de56fab7c89012d34e56fa7b8"
12+
13+
api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
14+
15+
solver = TwoCaptcha(api_key)
16+
17+
try:
18+
result = solver.vkcaptcha(redirect_uri='https://id.vk.ru/not_robot_captcha?domain=vk.com&session_token=eyJhbGciOiJBMjU2R0NN....',
19+
userAgent='Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.4348.100 Yandex/23.6.1.1107 Yowser/2.5 Safari/537.36',
20+
proxy={'type': 'HTTPS',
21+
'uri': 'login:password@IP_address:PORT'}
22+
)
23+
24+
25+
except Exception as e:
26+
sys.exit(e)
27+
28+
else:
29+
sys.exit('result: ' + str(result))

examples/vkcaptcha_options.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import sys
2+
import os
3+
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
4+
5+
from twocaptcha import TwoCaptcha
6+
7+
# in this example we store the API key inside environment variables that can be set like:
8+
# export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
9+
# set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
10+
# you can just set the API key directly to it's value like:
11+
# api_key="1abc234de56fab7c89012d34e56fa7b8"
12+
13+
api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
14+
15+
config = {
16+
'server': '2captcha.com', # can be also set to 'rucaptcha.com'
17+
'apiKey': api_key,
18+
'softId': 123,
19+
'defaultTimeout': 120,
20+
'recaptchaTimeout': 600,
21+
'pollingInterval': 10,
22+
'extendedResponse': True
23+
}
24+
25+
solver = TwoCaptcha(**config)
26+
27+
try:
28+
result = solver.vkcaptcha(redirect_uri='https://id.vk.ru/not_robot_captcha?domain=vk.com&session_token=eyJhbGciOiJBMjU2R0NN....',
29+
userAgent='Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.4348.100 Yandex/23.6.1.1107 Yowser/2.5 Safari/537.36',
30+
proxy={'type': 'HTTPS',
31+
'uri': 'login:password@IP_address:PORT'}
32+
)
33+
34+
35+
except Exception as e:
36+
sys.exit(e)
37+
38+
else:
39+
sys.exit('result: ' + str(result))

tests/test_vkcaptcha.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
12+
class VkCaptcha(AbstractTest):
13+
14+
15+
def test_all_params(self):
16+
17+
18+
params = {
19+
'redirect_uri': 'https://id.vk.ru/not_robot_captcha?domain=vk.com&session_token=eyJhbGciOiJBMjU2R0NN...',
20+
'userAgent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.4348.100 Yandex/23.6.1.1107 Yowser/2.5 Safari/537.36',
21+
'proxy': {'type': 'HTTPS',
22+
'uri': 'login:password@IP_address:PORT'}
23+
}
24+
25+
sends = {
26+
'method' : 'vkcaptcha',
27+
'redirect_uri': 'https://id.vk.ru/not_robot_captcha?domain=vk.com&session_token=eyJhbGciOiJBMjU2R0NN...',
28+
'useragent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.4348.100 Yandex/23.6.1.1107 Yowser/2.5 Safari/537.36',
29+
'proxytype': 'HTTPS',
30+
'proxy': 'login:password@IP_address:PORT'
31+
}
32+
33+
return self.send_return(sends, self.solver.vkcaptcha, **params)
34+
35+
36+
37+
38+
39+
if __name__ == '__main__':
40+
41+
unittest.main()
42+

twocaptcha/solver.py

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -962,12 +962,48 @@ def vkimage(self, files, steps, **kwargs):
962962
**kwargs)
963963
return result
964964

965-
def vkcaptcha(self, redirect_uri, userAgent, proxytype, proxy):
965+
def vkcaptcha(self, redirect_uri, userAgent, proxy, **kwargs):
966+
'''Wrapper for solving VK captcha using tokens.
966967
967-
result = self.solve(misery_key=misery_key,
968-
api_key=apikey,
969-
url=url,
970-
method='cutcaptcha',
968+
Parameters
969+
__________
970+
redirect_uri : str
971+
The URL that is returned for requests to the captchas API.
972+
userAgent : str
973+
User-Agent of the browser that will be used by the employee when loading the captcha.
974+
proxy : dict
975+
{'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
976+
'''
977+
978+
979+
result = self.solve(method='vkcaptcha',
980+
redirect_uri=redirect_uri,
981+
useragent=userAgent,
982+
proxy=proxy,
983+
**kwargs)
984+
return result
985+
986+
def captchafox(self, sitekey, pageurl, userAgent, proxy, **kwargs):
987+
'''Wrapper for solving VK captcha using tokens.
988+
989+
Parameters
990+
__________
991+
sitekey : str
992+
The sitekey parameter value found on the page or in network requests.
993+
pageurl : str
994+
Full URL of the page with captcha.
995+
userAgent : str
996+
User-Agent of the browser that will be used by the employee when loading the captcha.
997+
proxy : dict
998+
{'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
999+
'''
1000+
1001+
1002+
result = self.solve(method='captchafox',
1003+
sitekey=sitekey,
1004+
pageurl=pageurl,
1005+
useragent=userAgent,
1006+
proxy=proxy,
9711007
**kwargs)
9721008
return result
9731009

0 commit comments

Comments
 (0)