Passing custom parameters to CloudScraper
This commit is contained in:
parent
154b2c2d66
commit
64c27e568a
1 changed files with 26 additions and 5 deletions
|
@ -30,10 +30,34 @@ class AternosConnect:
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
|
|
||||||
self.session = CloudScraper()
|
self.cf_init = partial(CloudScraper)
|
||||||
|
self.session = self.cf_init()
|
||||||
self.sec = ''
|
self.sec = ''
|
||||||
self.token = ''
|
self.token = ''
|
||||||
|
|
||||||
|
def add_args(self, **kwargs) -> None:
|
||||||
|
|
||||||
|
"""Pass arguments to
|
||||||
|
CloudScarper session object __init__
|
||||||
|
|
||||||
|
Args:
|
||||||
|
**kwargs: Keyword arguments
|
||||||
|
"""
|
||||||
|
|
||||||
|
self.cf_init = partial(CloudScraper, **kwargs)
|
||||||
|
self.refresh_session()
|
||||||
|
|
||||||
|
def refresh_session(self) -> None:
|
||||||
|
|
||||||
|
"""Creates a new CloudScraper
|
||||||
|
session object and copies all cookies.
|
||||||
|
Required for bypassing Cloudflare"""
|
||||||
|
|
||||||
|
old_cookies = self.session.cookies
|
||||||
|
self.session = self.cf_init()
|
||||||
|
self.session.cookies.update(old_cookies)
|
||||||
|
del old_cookies
|
||||||
|
|
||||||
def parse_token(self) -> str:
|
def parse_token(self) -> str:
|
||||||
|
|
||||||
"""Parses Aternos ajax token that
|
"""Parses Aternos ajax token that
|
||||||
|
@ -143,10 +167,7 @@ class AternosConnect:
|
||||||
if retry <= 0:
|
if retry <= 0:
|
||||||
raise CloudflareError('Unable to bypass Cloudflare protection')
|
raise CloudflareError('Unable to bypass Cloudflare protection')
|
||||||
|
|
||||||
old_cookies = self.session.cookies
|
self.refresh_session()
|
||||||
self.session = CloudScraper()
|
|
||||||
self.session.cookies.update(old_cookies)
|
|
||||||
del old_cookies
|
|
||||||
|
|
||||||
params = params or {}
|
params = params or {}
|
||||||
data = data or {}
|
data = data or {}
|
||||||
|
|
Reference in a new issue