From b0d337064cfef98c9de0a1f322a673153ffee7ed Mon Sep 17 00:00:00 2001 From: Maxim S Date: Wed, 28 Aug 2024 13:31:19 +0200 Subject: [PATCH 1/8] - 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 --- README.md | 11 +++++++++++ examples/datadome.py | 34 ++++++++++++++++++++++++++++++++++ tests/datadome_test.py | 34 ++++++++++++++++++++++++++++++++++ twocaptcha/solver.py | 24 ++++++++++++++++++++++++ 4 files changed, 103 insertions(+) create mode 100644 examples/datadome.py create mode 100644 tests/datadome_test.py diff --git a/README.md b/README.md index d8c05cd..80ff362 100644 --- a/README.md +++ b/README.md @@ -407,6 +407,17 @@ result = solver.tencent(app_id="197326679", param1=..., ...) ``` +### DataDome + +[API method description.](https://2captcha.com/2captcha-api#datadome) + +Use this method to solve DataDome captcha. +```python +result = solver.datadome(captcha_url="https://geo.captcha-delivery.com/captcha/?initialCid=...", + pageurl="https://dd.burak.fr/", + param1=..., ...) +``` + ## Other methods ### send / get_result diff --git a/examples/datadome.py b/examples/datadome.py new file mode 100644 index 0000000..096145a --- /dev/null +++ b/examples/datadome.py @@ -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&cid=6UMFxKqnfKi2eFFrE1qXfCKp63PJZG8paEmhrdvBTCjLMsxEBnwN1ll6DMj3zgknV12vVMEGIGlz_PwXqp3KInLKNssKELeGAiA30KzBLiZkbsANFUppr57BQ~_~zqk7&referer=https%3A%2F%2Fdd.burak.fr%2F&hash=47C8DCE2BC1F24F1810FD12D144E2A&t=fe&s=39587&e=bec7a70727d6522cc2763179059323aa7d2faac7420c5da690fffd096a893c12", + pageurl="https://dd.burak.fr/", + 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)) \ No newline at end of file diff --git a/tests/datadome_test.py b/tests/datadome_test.py new file mode 100644 index 0000000..d6f29a5 --- /dev/null +++ b/tests/datadome_test.py @@ -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://dd.burak.fr/', + '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://dd.burak.fr/', + '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() \ No newline at end of file diff --git a/twocaptcha/solver.py b/twocaptcha/solver.py index f460baf..1eae27d 100755 --- a/twocaptcha/solver.py +++ b/twocaptcha/solver.py @@ -810,6 +810,30 @@ 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, optional + {'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 solve(self, timeout=0, polling_interval=0, **kwargs): '''Sends captcha, receives result. From a441ebb7ef591a08e6efef29d8557e30f86c4a21 Mon Sep 17 00:00:00 2001 From: Maxim S Date: Wed, 28 Aug 2024 13:59:38 +0200 Subject: [PATCH 2/8] - Minor edits to params of captcha Signed-off-by: Maxim S --- README.md | 2 +- examples/datadome.py | 4 ++-- tests/{datadome_test.py => test_datadome.py} | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) rename tests/{datadome_test.py => test_datadome.py} (89%) diff --git a/README.md b/README.md index 80ff362..b8954cf 100644 --- a/README.md +++ b/README.md @@ -414,7 +414,7 @@ result = solver.tencent(app_id="197326679", Use this method to solve DataDome captcha. ```python result = solver.datadome(captcha_url="https://geo.captcha-delivery.com/captcha/?initialCid=...", - pageurl="https://dd.burak.fr/", + pageurl="https://mysite.com/page/with/datadome", param1=..., ...) ``` diff --git a/examples/datadome.py b/examples/datadome.py index 096145a..08b222b 100644 --- a/examples/datadome.py +++ b/examples/datadome.py @@ -18,8 +18,8 @@ try: result = solver.datadome( - 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", - pageurl="https://dd.burak.fr/", + 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', diff --git a/tests/datadome_test.py b/tests/test_datadome.py similarity index 89% rename from tests/datadome_test.py rename to tests/test_datadome.py index d6f29a5..07f3d1e 100644 --- a/tests/datadome_test.py +++ b/tests/test_datadome.py @@ -13,7 +13,7 @@ class DatadomeTest(AbstractTest): def test_all_params(self): params = { 'captcha_url': 'https://geo.captcha-delivery.com/captcha/?initialCid=AHrlqAAAAAMAZirHgKBVrxwAsVuKlQ%3D%3D&c', - 'pageurl': 'https://dd.burak.fr/', + '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'} } @@ -21,7 +21,7 @@ def test_all_params(self): sends = { 'method': 'datadome', 'captcha_url': 'https://geo.captcha-delivery.com/captcha/?initialCid=AHrlqAAAAAMAZirHgKBVrxwAsVuKlQ%3D%3D&c', - 'pageurl': 'https://dd.burak.fr/', + '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' From 8d8665ab9a29259671dac9336299920ff11a3ef8 Mon Sep 17 00:00:00 2001 From: Maxim S Date: Wed, 28 Aug 2024 16:01:18 +0200 Subject: [PATCH 3/8] - Added link datadome to the table of contents - Minor edit to param in datadome.py Signed-off-by: Maxim S --- README.md | 1 + examples/datadome.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b8954cf..6dcf3af 100644 --- a/README.md +++ b/README.md @@ -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) - [Other methods](#other-methods) - [send / get_result](#send--get_result) - [balance](#balance) diff --git a/examples/datadome.py b/examples/datadome.py index 08b222b..7a62980 100644 --- a/examples/datadome.py +++ b/examples/datadome.py @@ -18,7 +18,7 @@ try: result = solver.datadome( - captcha_url="https://geo.captcha-delivery.com/captcha/?initialCid=AHrlqAAAAAMAZirHgKBVrxwAsVuKlQ%3D%3D&c", + 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={ From a5604e6f49e25c48d159fb9c67b57bf06fb1bcb0 Mon Sep 17 00:00:00 2001 From: dzmitry-duboyski Date: Thu, 29 Aug 2024 14:55:12 +0400 Subject: [PATCH 4/8] Update README.md --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 6dcf3af..8eb1a3f 100644 --- a/README.md +++ b/README.md @@ -413,9 +413,18 @@ result = solver.tencent(app_id="197326679", [API method description.](https://2captcha.com/2captcha-api#datadome) 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=..., ...) ``` @@ -567,3 +576,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 \ No newline at end of file From d33ef82b5b8a15372c1b34ad4966baa1e69d989e Mon Sep 17 00:00:00 2001 From: dzmitry-duboyski Date: Thu, 29 Aug 2024 15:04:38 +0400 Subject: [PATCH 5/8] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8eb1a3f..fee3664 100644 --- a/README.md +++ b/README.md @@ -501,7 +501,7 @@ 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. +keycaptcha, capy puzzle, lemin, atbcaptcha, turnstile, amazon waf, mtcaptcha, friendly captcha, cutcaptcha, Tencent, DataDome. The proxy will be forwarded to the API to solve the captcha. From 7405674eaf022f86463fc942893619c899970013 Mon Sep 17 00:00:00 2001 From: dzmitry-duboyski Date: Thu, 29 Aug 2024 15:07:09 +0400 Subject: [PATCH 6/8] Update keywords --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index bed8bd4..00be511 100644 --- a/setup.py +++ b/setup.py @@ -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'], + 'Capy Puzzle', 'MTCaptcha', 'Friendly Captcha', 'Tencent', 'Cutcaptcha', 'DataDome'], python_requires='>=3.6', test_suite='tests') From b0a3a2460537f8cfa7d8fba9608e91df7f869be9 Mon Sep 17 00:00:00 2001 From: Maxim S Date: Thu, 29 Aug 2024 13:23:07 +0200 Subject: [PATCH 7/8] - Minor fix in method documentation Signed-off-by: Maxim S --- twocaptcha/solver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/twocaptcha/solver.py b/twocaptcha/solver.py index 1eae27d..7909a54 100755 --- a/twocaptcha/solver.py +++ b/twocaptcha/solver.py @@ -821,7 +821,7 @@ def datadome(self, captcha_url, pageurl, userAgent, proxy, **kwargs): 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, optional + proxy : dict {'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}. """ From ba2ea80bcc19bf5552ebee118bb6d49596fe71fd Mon Sep 17 00:00:00 2001 From: dzmitry-duboyski Date: Thu, 29 Aug 2024 15:36:48 +0400 Subject: [PATCH 8/8] v1.3.0 --- twocaptcha/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/twocaptcha/__init__.py b/twocaptcha/__init__.py index 07e0892..e2776b6 100644 --- a/twocaptcha/__init__.py +++ b/twocaptcha/__init__.py @@ -12,4 +12,4 @@ """ __author__ = '2captcha' -__version__ = '1.2.8' +__version__ = '1.3.0'