Skip to content

Instantly share code, notes, and snippets.

@kafran
Last active November 11, 2022 14:44
Embed
What would you like to do?
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))
@Lewiscowles1986
Copy link

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