Get site cookies with Selenium using Python

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()

Posted

in

,

by

Tags: