Last active
January 9, 2025 14:57
-
-
Save garywill/a4547c0cbb4f67473621027416b98200 to your computer and use it in GitHub Desktop.
convert .har (Firefox browser log) to csv
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
#!/usr/bin/python3 | |
import json | |
import csv | |
json_file_text = "" | |
with open('INPUTHARJSONFILE') as file: | |
json_file_text = file.read() | |
j_obj = json.loads(json_file_text) | |
es = j_obj ['log'] ['entries'] | |
new_j = [] | |
for i in range(len(es)) : | |
et = es[i] | |
new_e = {} | |
new_e ['t'] = et ['startedDateTime'] | |
new_e ['status'] = str(et ['response'] ['status']) + ' ' + et['response']['statusText'] | |
new_e ['url'] = et ['request'] ['url'] | |
new_e ['method'] = et ['request'] ['method'] | |
new_e ['protocol'] = new_e ['url'] .split('://') [0] | |
new_e ['domain'] = new_e ['url'] .split('://') [1] .split('/')[0] | |
new_e ['file'] = new_e ['url'] .split('://') [1] .split('/')[-1] .split('?')[0] | |
new_e ['file_sfx'] = new_e ['file'] .split('.')[-1] | |
new_e ['minetype'] = et ['response'] ['content'] ['mimeType'] if et ['response'] ['content'] else '' | |
new_e ['bodysize'] = et ['response'] ['bodySize'] | |
new_j . append(new_e) | |
print(new_j) | |
keysList = list ( new_j[0].keys() ) | |
print(keysList) | |
with open("OUTPUTCSVFILE.csv", "w") as csvf: | |
writer = csv.DictWriter(csvf, fieldnames=keysList) | |
writer.writeheader() | |
for i in range(len(new_j)) : | |
print(i) | |
print(new_j[i]) | |
writer.writerow(new_j[i]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment