Skip to content

Commit be89b20

Browse files
author
Andrei
committed
Update datadome_slider.py
1 parent dc0643e commit be89b20

1 file changed

Lines changed: 32 additions & 83 deletions

File tree

Lines changed: 32 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
from typing import Union, Optional
1+
from typing import Union
22

33
from python3_capsolver.core.base import BaseCaptcha
4-
from python3_capsolver.core.enum import ProxyType
5-
from python3_capsolver.core.config import REQUEST_URL
6-
from python3_capsolver.core.serializer import CaptchaResponseSer, RequestCreateTaskSer, DatadomeSliderOptionsSer
4+
from python3_capsolver.core.enum import DatadomeSliderTypeEnm
5+
from python3_capsolver.core.serializer import DatadomeSliderSer, CaptchaResponseSer
76

87

98
class DatadomeSlider(BaseCaptcha):
@@ -14,22 +13,16 @@ class DatadomeSlider(BaseCaptcha):
1413
api_key: Capsolver API key
1514
websiteURL: Address of the webpage
1615
captchaUrl: Captcha Url where is the captcha
17-
proxyType: Type of the proxy
18-
proxyAddress: Proxy IP address IPv4/IPv6. Not allowed to use:
19-
host names instead of IPs,
20-
transparent proxies (where client IP is visible),
21-
proxies from local networks (192.., 10.., 127...)
22-
proxyPort: Proxy port.
23-
sleep_time: The waiting time between requests to get the result of the Captcha
24-
request_url: API address for sending requests
16+
proxy: Proxy data
17+
userAgent: Browser's User-Agent which is used in emulation
2518
2619
Examples:
2720
>>> DatadomeSlider(api_key="CAI-1324...",
21+
... captcha_type=DatadomeSliderTypeEnm.DatadomeSliderTask,
2822
... websiteURL="https://www.some-url.com/",
2923
... captchaUrl="https://www.some-url.com/to-page-with-captcha",
30-
... proxyType="http",
31-
... proxyAddress="0.0.0.0",
32-
... proxyPort=9090,
24+
... proxy="socks5:158.120.100.23:334:user:pass",
25+
... userAgent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36",
3326
... ).captcha_handler()
3427
CaptchaResponseSer(errorId=False,
3528
errorCode=None,
@@ -40,11 +33,11 @@ class DatadomeSlider(BaseCaptcha):
4033
)
4134
4235
>>> await DatadomeSlider(api_key="CAI-1324...",
36+
... captcha_type="DatadomeSliderTask",
4337
... websiteURL="https://www.some-url.com/",
4438
... captchaUrl="https://www.some-url.com/to-page-with-captcha",
45-
... proxyType="http",
46-
... proxyAddress="0.0.0.0",
47-
... proxyPort=9090,
39+
... proxy="socks5:158.120.100.23:334:user:pass",
40+
... userAgent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36",
4841
... ).aio_captcha_handler()
4942
CaptchaResponseSer(errorId=False,
5043
errorCode=None,
@@ -58,99 +51,55 @@ class DatadomeSlider(BaseCaptcha):
5851
CaptchaResponseSer model with full server response
5952
6053
Notes:
61-
https://captchaai.atlassian.net/wiki/spaces/CAPTCHAAI/pages/426393/
54+
https://docs.capsolver.com/guide/antibots/datadome.html
6255
"""
6356

6457
def __init__(
6558
self,
66-
api_key: str,
59+
captcha_type: Union[DatadomeSliderTypeEnm, str],
6760
websiteURL: str,
6861
captchaUrl: str,
69-
proxyType: Union[ProxyType, str],
70-
proxyAddress: str,
71-
proxyPort: int,
72-
sleep_time: Optional[int] = 5,
73-
request_url: Optional[str] = REQUEST_URL,
62+
proxy: str,
63+
userAgent: str,
64+
*args,
65+
**kwargs,
7466
):
7567

76-
super().__init__(
77-
api_key=api_key,
78-
sleep_time=sleep_time,
79-
request_url=request_url,
80-
)
68+
super().__init__(*args, **kwargs)
8169

82-
self.task_params = DatadomeSliderOptionsSer(**locals()).dict()
70+
if captcha_type in DatadomeSliderTypeEnm.list():
71+
self.task_params = DatadomeSliderSer(**locals()).dict()
72+
else:
73+
raise ValueError(
74+
f"""Invalid `captcha_type` parameter set for `{self.__class__.__name__}`,
75+
available - {DatadomeSliderTypeEnm.list()}"""
76+
)
77+
for key in kwargs:
78+
self.task_params.update({key: kwargs[key]})
8379

84-
def captcha_handler(
85-
self,
86-
**additional_params,
87-
) -> CaptchaResponseSer:
80+
def captcha_handler(self) -> CaptchaResponseSer:
8881
"""
89-
Synchronous method for captcha solving
90-
91-
Args:
92-
additional_params: Some additional parameters that will be used in creating the task
93-
and will be passed to the payload under ``task`` key.
94-
Like ``proxyPassword``, ``userAgent`` and etc. - more info in service docs
95-
96-
Examples:
97-
>>> DatadomeSlider(api_key="CAI-1324...",
98-
... websiteURL="https://www.some-url.com/",
99-
... captchaUrl="https://www.some-url.com/to-page-with-captcha",
100-
... proxyType="http",
101-
... proxyAddress="0.0.0.0",
102-
... proxyPort=9090,
103-
... ).captcha_handler()
104-
CaptchaResponseSer(errorId=False,
105-
errorCode=None,
106-
errorDescription=None,
107-
taskId='73bdcd28-6c77-4414-8....',
108-
status=<ResponseStatusEnm.Ready: 'ready'>,
109-
solution={'gRecaptchaResponse': '44795sds...'}
110-
)
82+
Sync method for captcha solving
11183
11284
Returns:
11385
CaptchaResponseSer model with full service response
11486
11587
Notes:
11688
Check class docstring for more info
11789
"""
118-
return self._processing_captcha(serializer=RequestCreateTaskSer, type=self.captcha_type, **additional_params)
90+
return self._processing_captcha(create_params=self.task_params)
11991

12092
async def aio_captcha_handler(
12193
self,
12294
**additional_params,
12395
) -> CaptchaResponseSer:
12496
"""
125-
Asynchronous method for captcha solving
126-
127-
Args:
128-
additional_params: Some additional parameters that will be used in creating the task
129-
and will be passed to the payload under ``task`` key.
130-
Like ``coordinate``, ``enterprisePayload`` and etc. - more info in service docs
131-
132-
Examples:
133-
>>> await DatadomeSlider(api_key="CAI-1324...",
134-
... websiteURL="https://www.some-url.com/",
135-
... captchaUrl="https://www.some-url.com/to-page-with-captcha",
136-
... proxyType="http",
137-
... proxyAddress="0.0.0.0",
138-
... proxyPort=9090,
139-
... ).aio_captcha_handler()
140-
CaptchaResponseSer(errorId=False,
141-
errorCode=None,
142-
errorDescription=None,
143-
taskId='73bdcd28-6c77-4414-8....',
144-
status=<ResponseStatusEnm.Ready: 'ready'>,
145-
solution={'gRecaptchaResponse': '44795sds...'}
146-
)
97+
Async method for captcha solving
14798
14899
Returns:
149100
CaptchaResponseSer model with full service response
150101
151102
Notes:
152103
Check class docstring for more info
153104
"""
154-
return await self._aio_processing_captcha(
155-
serializer=RequestCreateTaskSer, type=self.captcha_type, **additional_params
156-
)
105+
return await self._aio_processing_captcha(create_params=self.task_params)

0 commit comments

Comments
 (0)