Use uppercase instead of lowercase
This commit is contained in:
@@ -33,28 +33,28 @@ input("Press Enter to extract cookies...")
|
|||||||
all_cookies = driver.get_cookies()
|
all_cookies = driver.get_cookies()
|
||||||
|
|
||||||
# Define the cookie names we want (case-insensitive)
|
# Define the cookie names we want (case-insensitive)
|
||||||
target_names = {"compass", "ssid", "sid", "osid", "hsid"}
|
target_names = {"COMPASS", "SSID", "SID", "OSID", "HSID"}
|
||||||
extracted = {}
|
extracted = {}
|
||||||
|
|
||||||
# For COMPASS cookie, if multiple are present, prefer the one with path == "/"
|
# For COMPASS cookie, if multiple are present, prefer the one with path == "/"
|
||||||
compass_cookie = None
|
compass_cookie = None
|
||||||
|
|
||||||
for cookie in all_cookies:
|
for cookie in all_cookies:
|
||||||
name_lower = cookie["name"].lower()
|
name_upper = cookie["name"].upper()
|
||||||
if name_lower in target_names:
|
if name_upper in target_names:
|
||||||
# Process COMPASS cookie separately to pick the one with path '/'
|
# Process COMPASS cookie separately to pick the one with path '/'
|
||||||
if name_lower == "compass":
|
if name_upper == "COMPASS":
|
||||||
if cookie.get("path", "") == "/":
|
if cookie.get("path", "") == "/":
|
||||||
compass_cookie = cookie # select this cookie
|
compass_cookie = cookie # select this cookie
|
||||||
elif not compass_cookie:
|
elif not compass_cookie:
|
||||||
compass_cookie = cookie # take the first if none with '/' are found yet
|
compass_cookie = cookie # take the first if none with '/' are found yet
|
||||||
else:
|
else:
|
||||||
# For others, simply store the value
|
# For others, simply store the value
|
||||||
extracted[name_lower] = cookie["value"]
|
extracted[name_upper] = cookie["value"]
|
||||||
|
|
||||||
# If we found a COMPASS cookie, add it to the extracted dict.
|
# If we found a COMPASS cookie, add it to the extracted dict.
|
||||||
if compass_cookie:
|
if compass_cookie:
|
||||||
extracted["compass"] = compass_cookie["value"]
|
extracted["COMPASS"] = compass_cookie["value"]
|
||||||
|
|
||||||
# Form JSON object of the extracted cookies.
|
# Form JSON object of the extracted cookies.
|
||||||
json_data = json.dumps(extracted, indent=2)
|
json_data = json.dumps(extracted, indent=2)
|
||||||
|
|||||||
Reference in New Issue
Block a user