0

I'm trying to load cookies that already exist (they are in C:\Users\nicoc\AppData\Local\Google\Chrome\User Data\Default\Cookie) into a Selenium driver instance.

Now, I've read the fact that I can load cookies with the function driver.get_cookies() and save them with pickle but I don't want to launch a Selenium driver session and save the cookies, I need to load the already existing ones in some ways and attach them to a new Selenium driver session with something like:

cookies = pickle.load(cookiesfile)
         for cookie in cookies:
             driver.add_cookie(cookie)

I've also checked this answer https://stackoverflow.com/a/63158404/7848740 where he loads a .pkl file containing the cookies. Unfortunately, Google Chrome cookies have no format and, opening with a text editor, seems to be an SQLite3 database

I've also tried browsercookie https://pypi.org/project/browsercookie/ but it's not compatible with the latest Chrome versions

NictheDEV
  • 117
  • 7
  • i don't know that they need to be a pickle, couldn't you save them as a simple json, then read them in and assign each key:value? – SuperStew Oct 06 '21 at 14:37
  • @SuperStew the issue is that the file already exist so I'll probably need to load and open in someway and save it again in a format that _driver.add_cookie(cookie)_ read it but, I don't understand how to read the original Cookie file – NictheDEV Oct 06 '21 at 14:42
  • 1
    oh, if reading the pickle file is the issue, look up the docs for the pickle module. Should be lots of info – SuperStew Oct 06 '21 at 14:44
  • @SuperStew no, no, I know how to read a pickle. The problem is how to read the Cookie file inside the Chrome folder as it has no extension – NictheDEV Oct 06 '21 at 16:55

0 Answers0