Skip to content

Instantly share code, notes, and snippets.

Last active November 3, 2023 20:04
  • Star 3 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
Star You must be signed in to star a gist
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(
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))
with open(file, "wb") as f:
Copy link

Copy link

FurloSK commented Nov 3, 2023

Note that this gist will overwrite files with the same filename and different URL paths, since the code is not creating subfolders.

For updated version with subfolders creation and parametrised (specifiable) input file and output folder, see the fork here:

Copy link

kafran commented Nov 3, 2023

Thank you guys. This code is so old I barely remember it =)

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