break when the get_csrf is blocked
This commit is contained in:
@@ -6,6 +6,7 @@ import requests
|
||||
|
||||
from models.jsdata_le_pojo import JsDataLeTypePojo
|
||||
from models.jsdata_pojo import JsDataPojo
|
||||
from models.result_pojo import RequestResult
|
||||
from utils.get_only_datadome_cookies import get_datadome_cookies, get_app_cookies, get_lang_cookies, \
|
||||
retain_only_dataome_cookies
|
||||
from workers.proxies_constants import PROXY_LIST_FR
|
||||
@@ -24,7 +25,7 @@ class CaptchaResultGetter:
|
||||
self.cookie_str = 'datadome=5Nq~NEP_qQSHC0g_lZNnZmEv36J8gVV~rpZ329xmCkTq2~H3meIoXr4h_b988qB2XW5Te7iEGsvq8BzA5KeFupyrZFh4kgrDyl8hT2UymSByKHzAcDaNIBPDsRu2g_KG; Max-Age=31536000; Domain=.hermes.com; Path=/; Secure; SameSite=None'
|
||||
pass
|
||||
|
||||
def get_csrf(self, proxy_to_use, js_data: JsDataPojo, cookie: str = None) -> Union[str, None]:
|
||||
def get_csrf(self, proxy_to_use, js_data: JsDataPojo, cookie: str = None) -> Union[str, RequestResult]:
|
||||
if cookie is not None:
|
||||
headers = {'Content-Type': 'application/x-www-form-urlencoded',
|
||||
'User-Agent': js_data.ua,
|
||||
@@ -49,13 +50,16 @@ class CaptchaResultGetter:
|
||||
timeout=15)
|
||||
print(response.status_code)
|
||||
if response.status_code == 200:
|
||||
# print(response.text)
|
||||
print(response.url)
|
||||
print(response.text)
|
||||
return self.extract_csrf_from_html(response.text)
|
||||
elif response.status_code == 403:
|
||||
return RequestResult.BLOCKED
|
||||
else:
|
||||
return None
|
||||
print(response.text)
|
||||
return RequestResult.UNKNOWN
|
||||
except Exception as error:
|
||||
print(error)
|
||||
return RequestResult.PROXY_ERROR
|
||||
|
||||
def extract_csrf_from_html(self, html: str) -> Union[str, None]:
|
||||
result = re.findall(r'_csrf" value="[A-Za-z0-9-_]+', html)
|
||||
|
||||
Reference in New Issue
Block a user