Skip to content

Commit b0d3370

Browse files
committed
- Added datadome method to solver.py
- Added datadome.py to examples - Added datadome_test.py to tests - Added a description of the datadome method to README.md Signed-off-by: Maxim S <poplers24@gmail.com>
1 parent 6aef124 commit b0d3370

File tree

4 files changed

+103
-0
lines changed

4 files changed

+103
-0
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,17 @@ result = solver.tencent(app_id="197326679",
407407
param1=..., ...)
408408
```
409409

410+
### DataDome
411+
412+
<sup>[API method description.](https://2captcha.com/2captcha-api#datadome)</sup>
413+
414+
Use this method to solve DataDome captcha.
415+
```python
416+
result = solver.datadome(captcha_url="https://geo.captcha-delivery.com/captcha/?initialCid=...",
417+
pageurl="https://dd.burak.fr/",
418+
param1=..., ...)
419+
```
420+
410421
## Other methods
411422

412423
### send / get_result

examples/datadome.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import sys
2+
import os
3+
import json
4+
5+
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
6+
7+
from twocaptcha import TwoCaptcha
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 = TwoCaptcha(api_key)
18+
19+
try:
20+
result = solver.datadome(
21+
captcha_url="https://geo.captcha-delivery.com/captcha/?initialCid=AHrlqAAAAAMAZirHgKBVrxwAsVuKlQ%3D%3D&cid=6UMFxKqnfKi2eFFrE1qXfCKp63PJZG8paEmhrdvBTCjLMsxEBnwN1ll6DMj3zgknV12vVMEGIGlz_PwXqp3KInLKNssKELeGAiA30KzBLiZkbsANFUppr57BQ~_~zqk7&referer=https%3A%2F%2Fdd.burak.fr%2F&hash=47C8DCE2BC1F24F1810FD12D144E2A&t=fe&s=39587&e=bec7a70727d6522cc2763179059323aa7d2faac7420c5da690fffd096a893c12",
22+
pageurl="https://dd.burak.fr/",
23+
userAgent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36",
24+
proxy={
25+
'type': 'HTTP',
26+
'uri': 'login:password@IP_address:PORT'
27+
}
28+
)
29+
30+
except Exception as e:
31+
sys.exit(e)
32+
33+
else:
34+
sys.exit('result: ' + str(result))

tests/datadome_test.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 import AbstractTest
7+
except ImportError:
8+
from abstract import AbstractTest
9+
10+
11+
class DatadomeTest(AbstractTest):
12+
13+
def test_all_params(self):
14+
params = {
15+
'captcha_url': 'https://geo.captcha-delivery.com/captcha/?initialCid=AHrlqAAAAAMAZirHgKBVrxwAsVuKlQ%3D%3D&c',
16+
'pageurl': 'https://dd.burak.fr/',
17+
'userAgent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36',
18+
'proxy': {'type': 'HTTP', 'uri': 'login:password@IP_address:PORT'}
19+
}
20+
21+
sends = {
22+
'method': 'datadome',
23+
'captcha_url': 'https://geo.captcha-delivery.com/captcha/?initialCid=AHrlqAAAAAMAZirHgKBVrxwAsVuKlQ%3D%3D&c',
24+
'pageurl': 'https://dd.burak.fr/',
25+
'userAgent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36',
26+
'proxy': 'login:password@IP_address:PORT',
27+
'proxytype': 'HTTP'
28+
}
29+
30+
return self.send_return(sends, self.solver.datadome, **params)
31+
32+
33+
if __name__ == '__main__':
34+
unittest.main()

twocaptcha/solver.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,30 @@ def cutcaptcha(self, misery_key, apikey, url, **kwargs):
810810
**kwargs)
811811
return result
812812

813+
def datadome(self, captcha_url, pageurl, userAgent, proxy, **kwargs):
814+
"""Wrapper for solving DataDome Captcha.
815+
816+
Parameters
817+
__________
818+
captcha_url: str
819+
The value of the 'src' parameter for the 'iframe' element containing the captcha on the page.
820+
pageurl: str
821+
Full URL of the page that triggers the captcha when you go to it.
822+
userAgent: str
823+
User-Agent of the browser that will be used by the employee when loading the captcha.
824+
proxy : dict, optional
825+
{'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
826+
"""
827+
828+
result = self.solve(method='datadome',
829+
captcha_url=captcha_url,
830+
pageurl=pageurl,
831+
userAgent=userAgent,
832+
proxy=proxy,
833+
**kwargs)
834+
835+
return result
836+
813837
def solve(self, timeout=0, polling_interval=0, **kwargs):
814838
'''Sends captcha, receives result.
815839

0 commit comments

Comments
 (0)