Skip to content

Instantly share code, notes, and snippets.

@treble37
Forked from kafran/extract_har.py
Created September 3, 2022 23:35
Show Gist options
  • Save treble37/3c8b4263d8e91732582fc62a71763190 to your computer and use it in GitHub Desktop.
Save treble37/3c8b4263d8e91732582fc62a71763190 to your computer and use it in GitHub Desktop.
Python 3 script to extract images from HTTP Archive (HAR) files
import json
import base64
import os
# make sure the output directory exists before running!
folder = os.path.join(os.getcwd(), "imgs")
with open("scr.har", "r") as f:
har = json.loads(f.read())
entries = har["log"]["entries"]
for entry in entries:
mimetype = entry["response"]["content"]["mimeType"]
filename = entry["request"]["url"].split("/")[-1]
image64 = entry["response"]["content"]["text"]
if mimetype == "image/webp":
file = os.path.join(folder, "{}.webp".format(filename))
print(file)
with open(file, "wb") as f:
f.write(base64.b64decode(image64))
@treble37
Copy link
Author

treble37 commented Sep 3, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment