Skip to content

Commit c50d880

Browse files
Merge pull request #109 from 2captcha/RC-2935-datadome
RC-2935-datadome
2 parents 6aef124 + b0a3a24 commit c50d880

File tree

5 files changed

+116
-2
lines changed

5 files changed

+116
-2
lines changed

README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Examples of API requests for different captcha types are available on the [Pytho
4141
- [Friendly Captcha](#friendly-captcha)
4242
- [Cutcaptcha](#cutcaptcha)
4343
- [Tencent](#tencent)
44+
- [Datadome](#datadome)
4445
- [Other methods](#other-methods)
4546
- [send / get_result](#send--get_result)
4647
- [balance](#balance)
@@ -407,6 +408,26 @@ result = solver.tencent(app_id="197326679",
407408
param1=..., ...)
408409
```
409410

411+
### DataDome
412+
413+
<sup>[API method description.](https://2captcha.com/2captcha-api#datadome)</sup>
414+
415+
Use this method to solve DataDome captcha.
416+
417+
> [!IMPORTANT]
418+
> To solve the DataDome captcha, you must use a proxy. It is recommended to use [residential proxies].
419+
420+
```python
421+
result = solver.datadome(captcha_url="https://geo.captcha-delivery.com/captcha/?initialCid=...",
422+
pageurl="https://mysite.com/page/with/datadome",
423+
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",
424+
proxy={
425+
'type': 'HTTP',
426+
'uri': 'login:password@IP_address:PORT'
427+
},
428+
param1=..., ...)
429+
```
430+
410431
## Other methods
411432

412433
### send / get_result
@@ -480,7 +501,7 @@ except TimeoutException as e:
480501
## Proxies
481502

482503
You can pass your proxy as an additional argument for the following methods: recaptcha, funcaptcha, geetest, geetest v4, hcaptcha,
483-
keycaptcha, capy puzzle, lemin, atbcaptcha, turnstile, amazon waf, mtcaptcha, friendly captcha, cutcaptcha.
504+
keycaptcha, capy puzzle, lemin, atbcaptcha, turnstile, amazon waf, mtcaptcha, friendly captcha, cutcaptcha, Tencent, DataDome.
484505

485506
The proxy will be forwarded to the API to solve the captcha.
486507

@@ -555,3 +576,4 @@ The graphics and trademarks included in this repository are not covered by the M
555576
[Buy residential proxies]: https://2captcha.com/proxy/residential-proxies
556577
[Quick start]: https://2captcha.com/proxy?openAddTrafficModal=true
557578
[examples]: ./examples
579+
[residential proxies]: https://2captcha.com/proxy/residential-proxies

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&c...",
22+
pageurl="https://mysite.com/page/with/datadome",
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))

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', 'hCaptcha',
3737
'FunCaptcha', 'Geetest', 'image captcha', 'Coordinates', 'Click Captcha',
3838
'Geetest V4', 'Lemin captcha', 'Amazon WAF', 'Cloudflare Turnstile',
39-
'Capy Puzzle', 'MTCaptcha', 'Friendly Captcha', 'Tencent'],
39+
'Capy Puzzle', 'MTCaptcha', 'Friendly Captcha', 'Tencent', 'Cutcaptcha', 'DataDome'],
4040
python_requires='>=3.6',
4141
test_suite='tests')

tests/test_datadome.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://mysite.com/page/with/datadome',
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://mysite.com/page/with/datadome',
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
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)