SQLite storage model was inspired by Mozilla Firefox' cookies.sqlite.
When instanciated without a
filename, it places the file
python-cookies.sqlite in the home directory of the user (e.g.
from sqlitecookiejar import SQLiteCookieJar jar = SQLiteCookieJar() # the cookies will be stored in ~/python-cookies.sqlite jar.load() # load all the cookies from the file into the jar # Do stuff stuff with the cookies. You can eat them if you want. jar.save() # this will save all the cookies present in your jar
The module works like a charm with Kenneth Reitz' requests.
from sqlitecookiejar import SQLiteCookieJar from requests import Session path_to_jar = "/home/user/web/cookies/new_jar.sqlite" # set up a session with a brand new jar s = Session() s.cookies = SQLiteCookieJar(filename=path_to_jar) s.cookies.load() # empty s.get("http://cookie-giving-url.com") # now, you have cookies in your jar, you can save them s.cookies.save() jar = SQLiteCookieJar(filename=path_to_jar) jar.load() # contains the cookies given by cookie-giving-url.com # could be reused in another session
- The nature of the file at
filenameis discovered automatically. If the given file is not a database or if the database doesn't match the standard format, the constructor will raise an exception.
- This module is not compatible with the specific implementation of cookies in modern browsers, as the column names differ, and it lacks some columns.
- Expired cookies are flushed on every load.
- This implementation won't save session cookies or expired cookies. Parameters
ignore_expirescannot be set to True. This is not fully compatible with Python's cookielib.FilecookieJar but rather follows RFC 6265, at least on this specific aspect.
This module is released under the Apache v2 license.