Created
August 15, 2025 05:12
-
-
Save swateek/d5ff01eab1097d737e24b6181ae4ec5e to your computer and use it in GitHub Desktop.
Extract HTTP Requests From an HAR File
This file contains hidden or 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 json | |
| # Path to your HAR file | |
| har_file = "example.har" | |
| # Load HAR file | |
| with open(har_file, "r", encoding="utf-8") as f: | |
| har_data = json.load(f) | |
| # HAR files store entries under log.entries | |
| entries = har_data.get("log", {}).get("entries", []) | |
| requests_data = [] | |
| for entry in entries: | |
| request = entry.get("request", {}) | |
| url = request.get("url", "") | |
| # Skip requests to sentry.rightsense.ai, https://www.google-analytics.com | |
| if url.startswith("https://sentry.rightsense.ai") or url.startswith( | |
| "https://www.google-analytics.com" | |
| ): | |
| continue | |
| requests_data.append( | |
| { | |
| "method": request.get("method"), | |
| "url": request.get("url"), | |
| "headers": request.get("headers"), | |
| "queryString": request.get("queryString"), | |
| "postData": ( | |
| request.get("postData", {}).get("text") | |
| if request.get("postData") | |
| else None | |
| ), | |
| } | |
| ) | |
| # Print all requests | |
| for req in requests_data: | |
| print(f"{req['method']} {req['url']}") | |
| if req["postData"]: | |
| print("Body:", req["postData"]) | |
| print("-" * 80) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment