A powerful Python script for fetching content from any URL with advanced features including automatic cookie loading, authentication support, and SSL options.
- Universal URL Fetching: Works with any HTTP/HTTPS URL
- Automatic Cookie Loading: Load cookies from Chrome, Firefox, and Waterfox browsers (macOS)
- Authentication Support: Basic auth and custom headers
- SSL Options: Disable SSL verification for development/testing
- Confluence Integration: Special support for Confluence REST API
- File Output: Save content to files
- JSON Output: Machine-readable response format
- Comprehensive Error Handling: Detailed error reporting and debugging
- Python 3.6+
- macOS (for automatic cookie loading)
pip install requestsSave the script as url_fetcher.py and make it executable:
chmod +x url_fetcher.py# Basic URL fetch
python url_fetcher.py https://example.com
# Fetch with cookies from Chrome
python url_fetcher.py https://intranet.company.com --cookies chrome
# Fetch with authentication
python url_fetcher.py https://api.example.com -u username -p password
# Save to file
python url_fetcher.py https://example.com -o output.htmlpython url_fetcher.py <URL> [OPTIONS]| Option | Description |
|---|---|
URL |
The URL to fetch (required) |
-u, --username |
Username for authentication |
-p, --password |
Password or API token |
-o, --output |
Save content to file |
-H, --header |
Custom header (format: "Key: Value") |
-t, --timeout |
Request timeout in seconds (default: 30) |
--no-ssl-verify |
Disable SSL certificate verification |
--cookies |
Load cookies from browser (chrome, firefox, waterfox, auto) |
--json |
Output response as JSON |
--confluence |
Use Confluence API format |
# Simple GET request
python url_fetcher.py https://httpbin.org/get
# Fetch and save to file
python url_fetcher.py https://example.com -o page.html
# Get response as JSON
python url_fetcher.py https://api.github.com/users/octocat --json# Basic authentication
python url_fetcher.py https://protected-site.com -u admin -p secret123
# API token authentication
python url_fetcher.py https://api.example.com -u user -p api_token_here
# Custom authorization header
python url_fetcher.py https://api.example.com -H "Authorization: Bearer token123"# Load cookies from Chrome
python url_fetcher.py https://intranet.company.com --cookies chrome
# Load cookies from Firefox
python url_fetcher.py https://confluence.company.com --cookies firefox
# Try all available browsers
python url_fetcher.py https://site.com --cookies auto# Disable SSL verification for self-signed certificates
python url_fetcher.py https://localhost:8443/api --no-ssl-verify
# Development server with cookies
python url_fetcher.py https://dev.company.com --cookies chrome --no-ssl-verify# Fetch Confluence page using REST API
python url_fetcher.py https://company.atlassian.net/wiki/spaces/DOCS/pages/123456 \
--confluence -u email@company.com -p api_token
# With cookies (if already logged in)
python url_fetcher.py https://confluence.company.com/pages/123456 \
--confluence --cookies chrome# Multiple custom headers
python url_fetcher.py https://api.example.com \
-H "Accept: application/json" \
-H "User-Agent: MyApp/1.0" \
--json
# Complete example with all options
python url_fetcher.py https://secure-api.company.com/data \
-u apiuser -p secret123 \
--cookies chrome \
--no-ssl-verify \
-H "Accept: application/json" \
-t 60 \
-o response.json \
--jsonThe script automatically loads cookies from browser databases on macOS:
- Google Chrome:
~/Library/Application Support/Google/Chrome/Default/Cookies - Firefox:
~/Library/Application Support/Firefox/Profiles/*/cookies.sqlite - Waterfox:
~/Library/Application Support/Waterfox/Profiles/*/cookies.sqlite
- Automatically finds default browser profiles
- Filters out expired cookies
- Safely handles locked databases (creates temporary copies)
- Works with complex authentication systems
- Supports session persistence
- Auto Mode: Use
--cookies autoto try all available browsers - Corporate Networks: Great for accessing intranet sites you're already logged into
- Development: Perfect for testing authenticated endpoints
- Session Management: Maintains complex login states automatically
✅ Successfully fetched https://example.com
Status: 200
Content length: 1234 characters
Encoding: utf-8
==================================================
CONTENT:
==================================================
<!DOCTYPE html>...
{
"url": "https://example.com",
"status_code": 200,
"success": true,
"headers": {
"content-type": "text/html"
},
"content": "<!DOCTYPE html>...",
"content_length": 1234,
"encoding": "utf-8"
}The script provides detailed error information:
❌ Failed to fetch https://invalid-url.com
Error: HTTPSConnectionPool(host='invalid-url.com', port=443):
Max retries exceeded with url: / (Caused by NameResolutionError(...))Common error types:
- Connection errors: Network issues, invalid URLs
- Authentication errors: Wrong credentials, expired tokens
- SSL errors: Certificate issues, self-signed certs
- Timeout errors: Slow responses, unresponsive servers
- HTTP errors: 404, 500, etc.
- Default: SSL verification is enabled
- Development: Use
--no-ssl-verifyonly for trusted development environments - Warning: Disabling SSL verification removes protection against man-in-the-middle attacks
- Cookies are loaded from local browser databases
- Script creates temporary copies to avoid conflicts
- Only non-expired cookies are loaded
- Secure and HttpOnly flags are preserved
- Passwords can be provided via environment variables
- Use API tokens instead of passwords when possible
- Credentials are not logged or stored
"No cookies found"
# Check which browsers are available
python url_fetcher.py --cookies auto https://example.comSSL Certificate errors
# Disable SSL verification
python url_fetcher.py https://site.com --no-ssl-verifyPermission denied (cookies)
# Close browser and try again, or use different browser
python url_fetcher.py https://site.com --cookies firefoxTimeout errors
# Increase timeout
python url_fetcher.py https://slow-site.com -t 120- Use
--jsonfor machine-readable output - Check browser cookie locations manually
- Verify URLs are accessible in browser first
- Test with simple URLs before complex ones