Created
April 10, 2024 08:19
-
-
Save lukepearson/79e62c3635266612fd8644238b6f23b7 to your computer and use it in GitHub Desktop.
Mitmproxy image download script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from mitmproxy import http | |
import os | |
import hashlib | |
def response(flow: http.HTTPFlow) -> None: | |
save_dir = "downloaded_images" | |
os.makedirs(save_dir, exist_ok=True) | |
content_type = flow.response.headers.get("Content-Type", "") | |
if "image" in content_type: | |
url_hash = hashlib.sha256(flow.request.url.encode('utf-8')).hexdigest() | |
file_extension = content_type.split('/')[-1] | |
filename = f"{url_hash}.{file_extension}" | |
file_path = os.path.join(save_dir, filename) | |
with open(file_path, "wb") as f: | |
f.write(flow.response.content) | |
print(f"Image saved: {file_path}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment