1
0

Improve behaviour without cfscrape
Some checks failed
Build container / Package-Python (push) Failing after 26s
Build container / Package-Container (push) Successful in 1m44s

This commit is contained in:
Jon Michael Aanes 2024-04-18 00:02:13 +02:00
parent 0d7bb6fdf6
commit 553f6fe7d4
Signed by: Jmaa
SSH Key Fingerprint: SHA256:Ab0GfHGCblESJx7JRE4fj4bFy/KRpeLhi41y4pF3sNA

View File

@ -150,13 +150,17 @@ STANDARD_HEADERS = {
} }
class CachedCfScrape(requests_cache.CacheMixin, cfscrape.CloudflareScraper): if cfscrape:
class CachedCfScrape(requests_cache.CacheMixin, cfscrape.CloudflareScraper):
pass pass
def get_session(cookiejar, *, with_cfscrape: bool) -> requests.Session: def get_session(cookiejar, *, with_cfscrape: bool) -> requests.Session:
assert isinstance(with_cfscrape, bool) assert isinstance(with_cfscrape, bool)
session = CachedCfScrape('web_cache', cookies=cookiejar) session_class = requests_cache.CachedSession
if cfscrape:
session_class = CachedCfScrape
session = session_class('web_cache', cookies=cookiejar)
for cookie in cookiejar: for cookie in cookiejar:
session.cookies.set_cookie(cookie) session.cookies.set_cookie(cookie)
return session return session