Skip to main content

Extract cookies from URLs

Project description

MyCookie

A lightweight Python package for extracting and analyzing cookies from any URL.

Installation

pip install mycookie

Quick Start

Basic Usage

import mycookie

# Get cookie names from a URL
cookie_names = mycookie.url("https://example.com")
print(cookie_names)
# Output: ['sessionid', 'csrftoken', 'auth_token']

# Alternative function
cookie_names = mycookie.find_cookies("https://example.com")

Advanced Usage

from mycookie import CookieFinder

# Create a custom finder
finder = CookieFinder(user_agent="MyBot/1.0", timeout=30)

# Get just cookie names
names = finder.from_url("https://example.com")

# Get detailed cookie information
details = finder.from_url_with_details("https://example.com")

Usage Examples

Example 1: Basic Cookie Extraction

import mycookie

url = "https://httpbin.org/cookies/set/session/abc123"
cookies = mycookie.url(url)
print(cookies)

Output:

['session']

Example 2: Multiple Cookies

from mycookie import CookieFinder

finder = CookieFinder()
result = finder.from_url_with_details("https://httpbin.org/cookies/set?session=abc123&token=xyz789&user=john")

if result['success']:
    for cookie in result['cookies']:
        print(f"Name: {cookie['name']}")
        print(f"Value: {cookie['value']}")
        print(f"Domain: {cookie['domain']}")
        print(f"Secure: {cookie['secure']}")
        print("-" * 20)
    
    print(f"All cookie names: {result['cookie_names']}")

Output:

Name: session
Value: abc123
Domain: httpbin.org
Secure: False
--------------------
Name: token
Value: xyz789
Domain: httpbin.org
Secure: False
--------------------
Name: user
Value: john
Domain: httpbin.org
Secure: False
--------------------
All cookie names: ['session', 'token', 'user']

Example 3: Error Handling

import mycookie

try:
    cookies = mycookie.url("https://invalid-site-12345.com")
    print(cookies)
except Exception as e:
    print(f"Failed to fetch cookies: {type(e).__name__}")

Output:

Failed to fetch cookies: ConnectionError

Example 4: With Custom Headers

from mycookie import CookieFinder

finder = CookieFinder()
cookies = finder.from_url(
    "https://example.com",
    custom_headers={
        'Authorization': 'Bearer token123',
        'X-Custom-Header': 'value'
    }
)
print(cookies)

Example 5: Real Website Example

import mycookie

# Test on a real website
websites = [
    "https://github.com",
    "https://stackoverflow.com",
    "https://httpbin.org"
]

for site in websites:
    try:
        cookies = mycookie.url(site)
        print(f"{site}: {len(cookies)} cookie(s) found")
        if cookies:
            print(f"  Cookies: {', '.join(cookies)}")
    except Exception as e:
        print(f"{site}: Error - {type(e).__name__}")

Use Cases

  1. Security Testing: Check what cookies a website sets
  2. Web Scraping: Extract session cookies for authenticated scraping
  3. Monitoring: Track cookie changes on websites
  4. Debugging: Analyze cookie behavior during development
  5. Compliance: Check for secure cookie settings

License

MIT License

Links

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

For issues and questions:

  1. Check the GitHub Issues
  2. Create a new issue if needed

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

mycookie-0.0.1.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mycookie-0.0.1-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file mycookie-0.0.1.tar.gz.

File metadata

  • Download URL: mycookie-0.0.1.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.6

File hashes

Hashes for mycookie-0.0.1.tar.gz
Algorithm Hash digest
SHA256 7f8cbef8b8397ab495fca7e732af53bf14078c45936aea49837b5db0853ecff8
MD5 e9407bb5f6c24fcbfd024f6f4e7c9134
BLAKE2b-256 b45db06d95b309fa4d9771156ed721f843166590c58006ad9e8e257dbefff7ab

See more details on using hashes here.

File details

Details for the file mycookie-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: mycookie-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.6

File hashes

Hashes for mycookie-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6056a9cf240f442476f0c4a30bd8a45800a7dc4bfd193a7abaa8666645c06ca5
MD5 33a3d9f1f5c383980da10ca3992fce9a
BLAKE2b-256 399458268e82282ce40fdc44190985e13fbdfb25d90add7b9fd2d2dad94d8b37

See more details on using hashes here.

Supported by

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