Skip to content

Instantly share code, notes, and snippets.

@rene-d
Created January 5, 2026 10:00
Show Gist options
  • Select an option

  • Save rene-d/f22178a2e9934696c5c315d3cb8d108a to your computer and use it in GitHub Desktop.

Select an option

Save rene-d/f22178a2e9934696c5c315d3cb8d108a to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import tabulate
from pathlib import Path
import json
import base64
import sys
from urllib.parse import urlparse
import mimetypes
har = json.loads(Path(sys.argv[1]).read_text())
entries = har["log"]["entries"]
t = []
num = 0
for entry in entries:
mimetype = entry["response"]["content"]["mimeType"]
# if mimetype in ("text/css", "font/woff2", "image/gif"):
# continue
# size = entry["response"]["content"]["size"]
# if size == 0:
# continue
url = urlparse(entry["request"]["url"])
if any(
map(
url.hostname.endswith,
(
".google-analytics.com",
".snapchat.com",
".doubleclick.net",
),
)
):
print(f"skip {url.hostname}")
continue
path = Path(url.path)
filename = path.stem
response_text = entry["response"]["content"].get("text")
encoding = entry["response"]["content"].get("encoding")
shortened_path = url.path
if len(shortened_path) > 40:
shortened_path = shortened_path[:40] + "…"
suffix = mimetypes.guess_extension(mimetype)
if not suffix:
suffix = ".bin" if encoding == "base64" else ".txt"
num += 1
f = Path(f"r{num:03d}").with_suffix(suffix)
t.append(
(
f,
url.hostname,
shortened_path,
entry["response"]["content"]["size"],
mimetype,
len(response_text.encode()) if response_text else "",
encoding,
)
)
if response_text:
if encoding == "base64":
f.write_bytes(base64.b64decode(response_text))
elif encoding is None:
f.write_text(response_text)
else:
print(f"error encoding {encoding}")
exit()
print(tabulate.tabulate(t, tablefmt="fancy_outline"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment