-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhar_stripper.py
More file actions
33 lines (26 loc) · 1.03 KB
/
har_stripper.py
File metadata and controls
33 lines (26 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import sys
import os
def strip_har_file(input_path):
# Check if the file exists
if not os.path.isfile(input_path):
print(f"Error: File '{input_path}' not found.")
return
# Extract the filename and extension
base_name, ext = os.path.splitext(input_path)
output_path = f"{base_name}_stripped{ext}"
try:
with open(input_path, 'r', encoding='utf-8', errors='ignore') as infile, \
open(output_path, 'w', encoding='utf-8') as outfile:
for line in infile:
# Only write lines that are 1000 characters or shorter
if len(line) <= 1000:
outfile.write(line)
print(f"Successfully processed. Output saved to: {output_path}")
except Exception as e:
print(f"An error occurred: {e}")
if __name__ == "__main__":
# Ensure a filename was provided as an argument
if len(sys.argv) != 2:
print("Usage: python3 har_stripper.py {filename}.har")
else:
strip_har_file(sys.argv[1])