How to access the cookies database of firefox when firefox is running with python?

Viewed 776

I want to access the cookies programmatically which are stored in the cookies database on the filesystem. I tried to use this code, but it either gives a message

database is locked

when the browser is running, or does not yield any results when the browser has been quit (I assume all cookies are removed on the filesystem then?).

How can I programmatically access all cookies related to a browser session with python? I want to have a script that e.g. lists all the cookies on a terminal. How to do that? (Can be either chrome or firefox).

2 Answers

I tried the code you provided as a reference and it seemed to work when I did put manually the path to my cookies and made some minor changes to make the code work on Python 3.8. Are you running as Admin your cmdprompt (or sudo in terminal if Linux/Mac) ?

Basically you should be able to scrape the data you want from mydata after line 47 in the code and just print them out.

the problem is because that Firefox uses SQLite to obtain an EXCLUSIVE lock on the database (link)

the solution is to make a backup copy of the database befor read it

Related