Tue. Mar 28th, 2023

A brief example of how to store the cookies of a site in a python object using Selenium.

# Import webdriver
from selenium import webdriver

# Specify our target URL
url = 'https://www.moneyhelper.org.uk'

# Get our driver
DRIVER_BIN = "Webdrivers\msedgedriver.exe"
driver = webdriver.Edge(executable_path=DRIVER_BIN)

# Visit the URL
driver.get(url)

# Get all cookies
all_cookies = driver.get_cookies()

# Iterate through the cookies
for cookie in all_cookies:

    # Print the cookie
    print(cookie)

# Close the browser session
driver.close()

By admin