Harfetcher
   A professional-grade automation tool to automatically c
About the Project
A professional-grade automation tool to automatically capture and export HAR (HTTP Archive) files from Google Chrome using Selenium and the Chrome DevTools Protocol (CDP). HarFetcher doesn't just capture logsâit intelligently extracts the data into structured formats for easy analysis.
⨠Key Features
- ð Zero-Config Capture: Automatically generates a new HAR file on every page reload or navigation.
- ð ï¸ CDP Integration: Leverages
Chrome DevTools Protocolto capture full request/response bodies, including JSON APIs and HTML. - ð§ Smart Extraction: Automatically parses raw HAR files and organizes content into:
- API: REST/JSON payloads and endpoint data.
- Assets: JavaScript, CSS, and media files.
- Pages: Main HTML documents.
- ðª Cache Preservation: Operates without clearing the browser cache, allowing for realistic, stateful browsing sessions.
- ð Automated Workspace: Self-initializing folder structure to keep your data organized from the first run.
ðï¸ Architecture & How It Works
HarFetcher acts as a background observer for your Chrome session. Here's how the magic happens:
- CDP Enablement: It enables the
NetworkandPagedomains in Chrome's DevTools Protocol. - Performance Logging: Selenium captures performance entries which are then reconstructed into a valid HAR 1.2 format by
HARExporter. - Body Harvesting: For matching MIME types (JSON, Text, JS), it calls
Network.getResponseBodyto secure the actual payload. - Modular Storage:
FolderBuilderensures every snapshot is safely filed away with timestamped identifiers.
ð Project Structure
HarFetcher/ âââ output/ # Main data repository (Auto-generated) â âââ raw_har/ # Original .har files (Full capture) â âââ extracted/ # Processed and categorized data â â âââ api/ # API responses and JSON payloads â â âââ assets/ # Scripts, Stylesheets, and Media â â âââ pages/ # HTML source of navigated pages â âââ logs/ # Detailed application logs (app.log) âââ har_exporter.py # Core logic for CDP capture and HAR reconstruction âââ folder_builder.py # Handles directory initialization and pathing âââ main.py # Orchestration, Selenium setup, and event loop âââ requirements.txt # Project dependencies âââ README.md # You are here!
ð ï¸ Installation & Setup
1. Prerequisites
- Python 3.8+
- Google Chrome installed on your system.
2. Setup
Clone the repository and install the required dependencies:
# Create a virtual environment python -m venv venv # Activate the venv # On Windows: .\venv\Scripts\activate # On macOS/Linux: source venv/bin/activate # Install dependencies pip install -r requirements.txt
ð Usage
Running HarFetcher is straightforward:
- Start the script:
python main.py - Browse: The script will open a Chrome window. Any page you visit, reload, or navigate to will be automatically captured.
- Review: Check the
output/folder in real-time. You'll see.harfiles appearing inraw_har/and extracted content appearing inextracted/. - Exit: Close the browser window or press
Ctrl+Cin the terminal to safely shut down.
âï¸ Configuration
You can easily customize the behavior by editing main.py:
- Start URL: Change
driver.get("...")near line 55 to your desired landing page. - Polling Rate: Adjust
time.sleep(3)at the bottom of the loop to change how frequently it checks for new network activity. - Stabilization Delay: Adjust
time.sleep(2)beforegenerate_harto allow complex pages more time to finish loading before extraction.
ð¡ï¸ Troubleshooting
- Chromedriver Issues: We use
setup-chromedriverto handle pathing, but ensure your Chrome version is up to date. - Missing Bodies: Some responses (like large binary files or certain secure streams) might not be captureable via CDP
getResponseBody. - Windows Path Lengths: If you encounter
Errno 22, HarFetcher automatically hashes very long URLs to prevent Windows path length violations.
ð License
MIT © 2024 HarFetcher Team
Project Timeline
Technologies
External Links
Related Projects
Projects built with similar technologies.
Online Html Editor And Viewer
The Online HTML Editor and Viewer is a simple web application built with Flask that allows users to write and preview HTML code in real-time.
Qrgen
A premium, feature-rich QR Code Generator engineered with Python (Flask) and a pristine Glassmorphism frontend.
Examina Ai
Using AI, It transforms raw study materials into structured, verified examination sets with support for institutional export formats like Moodle XML.