Netscape Cookies

netscape-cookies
is a Python extension that simplifies the process of exporting Selenium WebDriver cookies into the Netscape HTTP Cookie format. This is useful when you need to use cookies in various tools that require the Netscape format.
Table of Contents
Installation
To install netscape-cookies
, simply run:
pip install netscape-cookies
Usage
Basic Usage
from netscape_cookies import save_cookies_to_file
from netscape_cookies import to_netscape_string
cookie_data = [
{
"domain": ".example.com",
"expiry": 1677649426,
"path": "/",
"secure": True,
"name": "cookie_name",
"value": "cookie_value"
}
]
file_path = "cookies.txt"
save_cookies_to_file(cookie_data, file_path)
to_netscape_string(cookie_data)
Example with Selenium WebDriver
from selenium import webdriver
from selnet_cookies import save_cookies_to_file
from netscape_cookies import to_netscape_string
browser = webdriver.Firefox()
browser.get("https://www.example.com")
cookie_data = browser.get_cookies()
file_path = "cookies.txt"
save_cookies_to_file(cookie_data, file_path)
to_netscape_string(cookie_data)
browser.quit()
Functions
netscape-cookies
provides the following functions:
to_netscape_string(cookie_data: List[Dict[str, Any]]) -> str
: Converts the given Selenium WebDriver cookie data into a Netscape HTTP Cookie formatted string.
save_cookies_to_file(cookie_data: List[Dict[str, Any]], file_path: str) -> None
: Saves the given Selenium WebDriver cookie data to a file in the Netscape HTTP Cookie format.
Contributing
Contributions to netscape-cookies
are welcome!
License
netscape-cookies
is released under the MIT License.