Skip to main content

Convert Cookies to Netscape format

Project description

Netscape Cookies

Python Version PyPI Version License

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

  1. Installation
  2. Usage
  3. Functions
  4. Contributing
  5. License

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

# Your Selenium WebDriver cookies
cookie_data = [
    {
        "domain": ".example.com",
        "expiry": 1677649426,
        "path": "/",
        "secure": True,
        "name": "cookie_name",
        "value": "cookie_value"
    }
]

file_path = "cookies.txt"

# Save cookies to file in Netscape format
save_cookies_to_file(cookie_data, file_path)

# Get cookies as String in Netscape format
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")

# Get cookies from Selenium WebDriver
cookie_data = browser.get_cookies()

file_path = "cookies.txt"

# Save cookies to file in Netscape format
save_cookies_to_file(cookie_data, file_path)

# Get cookies as String in Netscape format
to_netscape_string(cookie_data)

browser.quit()

Functions

netscape-cookies provides the following functions:

  1. to_netscape_string(cookie_data: List[Dict[str, Any]]) -> str: Converts the given Selenium WebDriver cookie data into a Netscape HTTP Cookie formatted string.
  2. 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

netscape-cookies-1.0.0.tar.gz (2.7 kB view details)

Uploaded Source

Built Distribution

netscape_cookies-1.0.0-py3-none-any.whl (2.9 kB view details)

Uploaded Python 3

File details

Details for the file netscape-cookies-1.0.0.tar.gz.

File metadata

  • Download URL: netscape-cookies-1.0.0.tar.gz
  • Upload date:
  • Size: 2.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.12

File hashes

Hashes for netscape-cookies-1.0.0.tar.gz
Algorithm Hash digest
SHA256 5839adae53faf6b71ba507b4003ecab99e2024b153320301db9ce3c390a2b0c6
MD5 b85ab6f650d73e5f9d1878fe0be0df96
BLAKE2b-256 617b5b0d5452d75dbafc3cdde67b89ac74a5b5a2105cf614b2d0ecba7a9b3350

See more details on using hashes here.

File details

Details for the file netscape_cookies-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for netscape_cookies-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cbd464f06fed2f129a4297834110265a36d221254cfe1e71c0fd3f0dc8126d9a
MD5 f1d217be1df4bb85d4a72e892d400c23
BLAKE2b-256 c29df4c693ea247b88ff84c6c683caea7477441f877fa456cea654b1c2015c62

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page