Skip to content

Commit

Permalink
Merge branch 'master' into RC-2938-cybersiara
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmitry-duboyski authored Aug 30, 2024
2 parents 1b130c0 + ba2ea80 commit 9fe05d6
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 4 deletions.
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Examples of API requests for different captcha types are available on the [Pytho
- [Friendly Captcha](#friendly-captcha)
- [Cutcaptcha](#cutcaptcha)
- [Tencent](#tencent)
- [Datadome](#datadome)
- [CyberSiARA](#cybersiara)
- [Other methods](#other-methods)
- [send / get_result](#send--get_result)
Expand Down Expand Up @@ -408,6 +409,26 @@ result = solver.tencent(app_id="197326679",
param1=..., ...)
```

### DataDome

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

Use this method to solve DataDome captcha.

> [!IMPORTANT]
> To solve the DataDome captcha, you must use a proxy. It is recommended to use [residential proxies].
```python
result = solver.datadome(captcha_url="https://geo.captcha-delivery.com/captcha/?initialCid=...",
pageurl="https://mysite.com/page/with/datadome",
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",
proxy={
'type': 'HTTP',
'uri': 'login:password@IP_address:PORT'
},
param1=..., ...)
```

### CyberSiARA

<sup>[API method description.](https://2captcha.com/2captcha-api#cybersiara)</sup>
Expand Down Expand Up @@ -493,7 +514,8 @@ except TimeoutException as e:
## Proxies

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


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

Expand Down Expand Up @@ -568,3 +590,4 @@ The graphics and trademarks included in this repository are not covered by the M
[Buy residential proxies]: https://2captcha.com/proxy/residential-proxies
[Quick start]: https://2captcha.com/proxy?openAddTrafficModal=true
[examples]: ./examples
[residential proxies]: https://2captcha.com/proxy/residential-proxies
34 changes: 34 additions & 0 deletions examples/datadome.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import sys
import os
import json

sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))

from twocaptcha import TwoCaptcha

# in this example we store the API key inside environment variables that can be set like:
# export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
# set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
# you can just set the API key directly to it's value like:
# api_key="1abc234de56fab7c89012d34e56fa7b8"

api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')

solver = TwoCaptcha(api_key)

try:
result = solver.datadome(
captcha_url="https://geo.captcha-delivery.com/captcha/?initialCid=AHrlqAAAAAMAZirHgKBVrxwAsVuKlQ%3D%3D&c...",
pageurl="https://mysite.com/page/with/datadome",
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",
proxy={
'type': 'HTTP',
'uri': 'login:password@IP_address:PORT'
}
)

except Exception as e:
sys.exit(e)

else:
sys.exit('result: ' + str(result))
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ def get_version():
'2captcha', 'captcha', 'api', 'captcha solver', 'reCAPTCHA', 'hCaptcha',
'FunCaptcha', 'Geetest', 'image captcha', 'Coordinates', 'Click Captcha',
'Geetest V4', 'Lemin captcha', 'Amazon WAF', 'Cloudflare Turnstile',
'Capy Puzzle', 'MTCaptcha', 'Friendly Captcha', 'Tencent', 'cybersiara'],
'Capy Puzzle', 'MTCaptcha', 'Friendly Captcha', 'Tencent', 'Cutcaptcha', 'DataDome', 'cybersiara'],
python_requires='>=3.6',
test_suite='tests')
34 changes: 34 additions & 0 deletions tests/test_datadome.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env python3

import unittest

try:
from .abstract import AbstractTest
except ImportError:
from abstract import AbstractTest


class DatadomeTest(AbstractTest):

def test_all_params(self):
params = {
'captcha_url': 'https://geo.captcha-delivery.com/captcha/?initialCid=AHrlqAAAAAMAZirHgKBVrxwAsVuKlQ%3D%3D&c',
'pageurl': 'https://mysite.com/page/with/datadome',
'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',
'proxy': {'type': 'HTTP', 'uri': 'login:password@IP_address:PORT'}
}

sends = {
'method': 'datadome',
'captcha_url': 'https://geo.captcha-delivery.com/captcha/?initialCid=AHrlqAAAAAMAZirHgKBVrxwAsVuKlQ%3D%3D&c',
'pageurl': 'https://mysite.com/page/with/datadome',
'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',
'proxy': 'login:password@IP_address:PORT',
'proxytype': 'HTTP'
}

return self.send_return(sends, self.solver.datadome, **params)


if __name__ == '__main__':
unittest.main()
2 changes: 1 addition & 1 deletion twocaptcha/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
"""

__author__ = '2captcha'
__version__ = '1.2.8'
__version__ = '1.3.0'
24 changes: 23 additions & 1 deletion twocaptcha/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,29 @@ def cutcaptcha(self, misery_key, apikey, url, **kwargs):
**kwargs)
return result

def datadome(self, captcha_url, pageurl, userAgent, proxy, **kwargs):
"""Wrapper for solving DataDome Captcha.
Parameters
__________
captcha_url: str
The value of the 'src' parameter for the 'iframe' element containing the captcha on the page.
pageurl: str
Full URL of the page that triggers the captcha when you go to it.
userAgent: str
User-Agent of the browser that will be used by the employee when loading the captcha.
proxy : dict
{'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
"""

result = self.solve(method='datadome',
captcha_url=captcha_url,
pageurl=pageurl,
userAgent=userAgent,
proxy=proxy,
**kwargs)
return result

def cybersiara(self, master_url_id, pageurl, userAgent, **kwargs):
'''Wrapper for solving CyberSiARA captcha.
Expand All @@ -829,7 +852,6 @@ def cybersiara(self, master_url_id, pageurl, userAgent, **kwargs):
pageurl=pageurl,
userAgent=userAgent,
**kwargs)

return result

def solve(self, timeout=0, polling_interval=0, **kwargs):
Expand Down

0 comments on commit 9fe05d6

Please sign in to comment.