-
-
Save treble37/3c8b4263d8e91732582fc62a71763190 to your computer and use it in GitHub Desktop.
Python 3 script to extract images from HTTP Archive (HAR) files
This file contains 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
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)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See fork https://gist.github.com/Lewiscowles1986/645e79295efa84698f4e45cd06d610ea if you want to get jpeg+png+webp