I am trying to access a webpage, save the cookie to a csv file, and then use cookie later all with selenium and python. Currently, I can save cookies perfectly fine, but then when I try to use that cookie later, I get the following error:
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: missing 'cookie'
(Session info: chrome=84.0.4147.89)
Here is my code to save the cookie:
from selenium import webdriver
import csv
outputdata = open('cookietest.csv', 'w', newline='')
outputWriter = csv.writer(outputdata)
driver=webdriver.Chrome()
driver.get("https://stackoverflow.com/")
cookies = driver.get_cookies()
print(cookies)
outputWriter.writerow([cookies])
And here is my code to load a webpage with thus cookies:
import csv
from selenium import webdriver
cookielist = open('cookietest.csv')
cookiereader = csv.reader(cookielist)
cookiedata = list(cookiereader)
curcookie = cookiedata[0][0]
driver=webdriver.Chrome()
driver.get("https://stackoverflow.com/")
driver.add_cookie(curcookie)
Does anyone have any ideas as to what I am doing wrong?
Thanks!