commit 79b77345cf0233d152147e670172ca9b45fea61e Author: TaurusXin Date: Tue May 6 20:03:18 2025 +0800 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..505a3b1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +# Python-generated files +__pycache__/ +*.py[oc] +build/ +dist/ +wheels/ +*.egg-info + +# Virtual environments +.venv diff --git a/.python-version b/.python-version new file mode 100644 index 0000000..e4fba21 --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.12 diff --git a/README.md b/README.md new file mode 100644 index 0000000..4630676 --- /dev/null +++ b/README.md @@ -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 +``` \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..931886f --- /dev/null +++ b/main.py @@ -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() diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..46b0b44 --- /dev/null +++ b/pyproject.toml @@ -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 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..5c58832 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +browser-cookie3>=0.19.1 +argparse>=1.4.0 \ No newline at end of file diff --git a/uv.lock b/uv.lock new file mode 100644 index 0000000..e31817b --- /dev/null +++ b/uv.lock @@ -0,0 +1,8 @@ +version = 1 +revision = 2 +requires-python = ">=3.12" + +[[package]] +name = "get-cookies" +version = "0.1.0" +source = { virtual = "." }