From 1a569296caf462d4a5a3df061c87afbcaf4e51d9 Mon Sep 17 00:00:00 2001 From: John Ogle Date: Mon, 17 Feb 2025 11:51:05 -0800 Subject: [PATCH] Refactor cookie extraction a bit --- selenium_cookie_extractor_json.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/selenium_cookie_extractor_json.py b/selenium_cookie_extractor_json.py index 8b8d822..b3e394a 100644 --- a/selenium_cookie_extractor_json.py +++ b/selenium_cookie_extractor_json.py @@ -41,18 +41,16 @@ compass_cookie = None for cookie in all_cookies: name_upper = cookie["name"].upper() - if name_upper in target_names: - # Process COMPASS cookie separately to pick the one with path '/' - if name_upper == "COMPASS": - if cookie.get("path", "") == "/": - compass_cookie = cookie # select this cookie - elif not compass_cookie: - compass_cookie = cookie # take the first if none with '/' are found yet - else: - # For others, simply store the value - extracted[name_upper] = cookie["value"] + if name_upper not in target_names: + continue + if name_upper == "COMPASS": + if cookie.get("path", "") == "/": + compass_cookie = cookie + elif compass_cookie is None: + compass_cookie = cookie + else: + extracted[name_upper] = cookie["value"] -# If we found a COMPASS cookie, add it to the extracted dict. if compass_cookie: extracted["COMPASS"] = compass_cookie["value"]