From fb1389401b0b11c0c9a255fca124a59cb0c7844b Mon Sep 17 00:00:00 2001 From: "Tanner Collin (aider)" Date: Thu, 22 May 2025 16:58:09 -0600 Subject: [PATCH] feat: Add script to parse HAR and list URLs --- har_parser.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 har_parser.py diff --git a/har_parser.py b/har_parser.py new file mode 100644 index 0000000..243787b --- /dev/null +++ b/har_parser.py @@ -0,0 +1,43 @@ +import json + +def main(): + """ + Opens a HAR archive file "data.har" and prints a list of files (URLs) + found in the archive. + """ + har_file_path = "data.har" + try: + with open(har_file_path, 'r', encoding='utf-8') as f: + har_data = json.load(f) + except FileNotFoundError: + print(f"Error: The file '{har_file_path}' was not found.") + return + except json.JSONDecodeError: + print(f"Error: Could not decode JSON from the file '{har_file_path}'.") + return + except Exception as e: + print(f"An unexpected error occurred while reading the file: {e}") + return + + try: + entries = har_data.get('log', {}).get('entries', []) + if not entries: + print("No entries found in the HAR file.") + return + + print("Files found in the HAR archive:") + for entry in entries: + request = entry.get('request', {}) + url = request.get('url') + if url: + print(url) + else: + print("Entry found with no request URL.") + except AttributeError: + print("Error: The HAR file does not have the expected structure ('log' or 'entries' missing).") + except Exception as e: + print(f"An unexpected error occurred while processing HAR entries: {e}") + + +if __name__ == "__main__": + main()