Created
June 25, 2020 18:38
-
-
Save jaames/74c8cfc7039d5d9147716a3b796d24bc to your computer and use it in GitHub Desktop.
Redownload content from a given .saz Fiddler dump
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 zipfile | |
import re | |
import urllib.request | |
from pathlib import Path | |
from sys import argv | |
if len(argv) < 3: | |
print('usage:') | |
print('python3 sazrip.py < input.saz > < output dir >') | |
exit() | |
saz = zipfile.ZipFile(argv[1]) | |
file_names = saz.namelist() | |
file_name_pattern = re.compile('^raw/([0-9]+)_c.txt$') | |
header_pattern = re.compile('^GET\s+(\S+)\s+') | |
for file_name in file_names: | |
file_match = file_name_pattern.match(file_name) | |
if file_match: | |
i = file_match.group(1) | |
print('loading', i) | |
with saz.open(file_name) as src: | |
data = src.read() | |
url_match = header_pattern.match(data.decode()) | |
if url_match: | |
url = url_match.group(1) | |
file_path = Path(url + '_' + i) | |
file_path_dir = file_path.parent.relative_to(argv[2]) | |
file_path_dir.mkdir(parents=True, exist_ok=True) | |
urllib.request.urlretrieve(url, file_path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment