init
This commit is contained in:
commit
79b77345cf
10
.gitignore
vendored
Normal file
10
.gitignore
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
# Python-generated files
|
||||||
|
__pycache__/
|
||||||
|
*.py[oc]
|
||||||
|
build/
|
||||||
|
dist/
|
||||||
|
wheels/
|
||||||
|
*.egg-info
|
||||||
|
|
||||||
|
# Virtual environments
|
||||||
|
.venv
|
1
.python-version
Normal file
1
.python-version
Normal file
@ -0,0 +1 @@
|
|||||||
|
3.12
|
18
README.md
Normal file
18
README.md
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# Chrome Cookie Extractor
|
||||||
|
|
||||||
|
A simple Python application that extracts cookies from Chrome for a specific website.
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
- Python 3.6+
|
||||||
|
- uv package manager
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
```bash
|
||||||
|
uv venv
|
||||||
|
uv pip install -r requirements.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
```bash
|
||||||
|
python main.py --url <website_url>
|
||||||
|
```
|
52
main.py
Normal file
52
main.py
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
import argparse
|
||||||
|
import json
|
||||||
|
import sys
|
||||||
|
import browser_cookie3
|
||||||
|
|
||||||
|
def get_cookies(url):
|
||||||
|
"""
|
||||||
|
Get cookies from Chrome for a specific URL
|
||||||
|
|
||||||
|
Args:
|
||||||
|
url (str): The URL to get cookies for
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
dict: Dictionary of cookies
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
# Extract domain from url
|
||||||
|
if url.startswith('http://'):
|
||||||
|
domain = url[7:].split('/')[0]
|
||||||
|
elif url.startswith('https://'):
|
||||||
|
domain = url[8:].split('/')[0]
|
||||||
|
else:
|
||||||
|
domain = url.split('/')[0]
|
||||||
|
|
||||||
|
# Get cookies from Chrome
|
||||||
|
chrome_cookies = browser_cookie3.chrome(domain_name=domain)
|
||||||
|
|
||||||
|
# Convert cookies to dictionary
|
||||||
|
cookies = {}
|
||||||
|
for cookie in chrome_cookies:
|
||||||
|
cookies[cookie.name] = cookie.value
|
||||||
|
|
||||||
|
return cookies
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error: {e}")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
def main():
|
||||||
|
parser = argparse.ArgumentParser(description='Extract cookies from Chrome for a specific URL')
|
||||||
|
parser.add_argument('--url', type=str, required=True, help='URL to extract cookies from')
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
cookies = get_cookies(args.url)
|
||||||
|
|
||||||
|
if cookies:
|
||||||
|
print(json.dumps(cookies, indent=4))
|
||||||
|
else:
|
||||||
|
print("No cookies found for this URL")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
11
pyproject.toml
Normal file
11
pyproject.toml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
[project]
|
||||||
|
name = "get-cookies"
|
||||||
|
version = "0.1.0"
|
||||||
|
description = "Add your description here"
|
||||||
|
readme = "README.md"
|
||||||
|
requires-python = ">=3.12"
|
||||||
|
dependencies = []
|
||||||
|
|
||||||
|
[[tool.uv.index]]
|
||||||
|
url = "https://pypi.tuna.tsinghua.edu.cn/simple"
|
||||||
|
default = true
|
2
requirements.txt
Normal file
2
requirements.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
browser-cookie3>=0.19.1
|
||||||
|
argparse>=1.4.0
|
Loading…
x
Reference in New Issue
Block a user