Skip to content

Commit

Permalink
- Added datadome method to solver.py
Browse files Browse the repository at this point in the history
- 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 <[email protected]>
  • Loading branch information
poplers24 committed Aug 28, 2024
1 parent 6aef124 commit b0d3370
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,17 @@ 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.
```python
result = solver.datadome(captcha_url="https://geo.captcha-delivery.com/captcha/?initialCid=...",
pageurl="https://dd.burak.fr/",
param1=..., ...)
```

## Other methods

### send / get_result
Expand Down
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&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))
34 changes: 34 additions & 0 deletions tests/datadome_test.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://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()
24 changes: 24 additions & 0 deletions twocaptcha/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit b0d3370

Please sign in to comment.