From 0efe0494b00530a137486438d952be24ea46b9b0 Mon Sep 17 00:00:00 2001 From: flencydoc Date: Tue, 21 Dec 2021 06:15:07 +0000 Subject: [PATCH] Added docstrings to several undocumented functions. --- cfscrape/__init__.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/cfscrape/__init__.py b/cfscrape/__init__.py index 251dc29..2977c41 100644 --- a/cfscrape/__init__.py +++ b/cfscrape/__init__.py @@ -102,6 +102,11 @@ def __init__(self, *args, **kwargs): @staticmethod def is_cloudflare_iuam_challenge(resp): + """ + :param resp: The HTTP response object + :returns: True if the response is a + Cloudflare challenge, False otherwise + """ return ( resp.status_code in (503, 429) and resp.headers.get("Server", "").startswith("cloudflare") @@ -111,6 +116,14 @@ def is_cloudflare_iuam_challenge(resp): @staticmethod def is_cloudflare_captcha_challenge(resp): + """ + Checks if the response is a Cloudflare captcha challenge. + + :param resp: The + HTTP response to check. + :returns bool: True if the response is a Cloudflare + captcha challenge, False otherwise. + """ return ( resp.status_code == 403 and resp.headers.get("Server", "").startswith("cloudflare") @@ -138,6 +151,13 @@ def cloudflare_is_bypassed(self, url, resp=None): ) def handle_captcha_challenge(self, resp, url): + """ + Cloudflare captcha challenge presented for `urlparse(url).netloc` (cfscrape + cannot solve captchas) + + If you are using OpenSSL 1.1.0 or lower, it is + recommended to upgrade your OpenSSL library and recompile Python. + """ error = ( "Cloudflare captcha challenge presented for %s (cfscrape cannot solve captchas)" % urlparse(url).netloc @@ -245,6 +265,14 @@ def solve_cf_challenge(self, resp, **original_kwargs): def solve_challenge(self, body, domain): + """ + Solve the Cloudflare challenge by using JavaScript to compute the + challenge. + + :param body: The HTTP response body from Cloudflare. + :param + domain: The domain we are solving for (used in JS). + """ try: all_scripts = re.findall(r'\