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
- Security Testing: Check what cookies a website sets
- Web Scraping: Extract session cookies for authenticated scraping
- Monitoring: Track cookie changes on websites
- Debugging: Analyze cookie behavior during development
- 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:
- Check the GitHub Issues
- Create a new issue if needed
Project details
Release history Release notifications | RSS feed
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)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters