HTML to MHTML Converter
Convert any webpage into a single .mhtml file, embedding all resources (images, CSS, JS) for offline viewing. Output format is compatible with Chrome/Edge browsers.
Usage
python ~/.qclaw/skills/html-to-mhtml/scripts/html_to_mhtml.py "<URL>" [output.mhtml]
Examples:
# Save to auto-generated filename
python html_to_mhtml.py "https://example.com"
# Specify output filename
python html_to_mhtml.py "https://news.ycombinator.com" "hn_archive.mhtml"
# Save Chinese webpage
python html_to_mhtml.py "https://www.baidu.com" "baidu_home.mhtml"
Parameters
| Parameter | Required | Description | |-----------|----------|-------------| | URL | Yes | Webpage URL to convert | | output | No | Output .mhtml filename (auto-generated if omitted) |
Features
- Downloads complete webpage with all linked resources
- Embeds images, CSS, JavaScript into single file
- Chrome-compatible MHTML format (Blink format)
- Quoted-printable encoding for text, base64 for binary
- Proper Content-ID and cid: reference handling
- Opens in Chrome, Edge, and other MHTML-compatible browsers
Dependencies
pip install -r requirements.txt
Technical Notes
The script generates MHTML in Chrome's native format:
From: <Saved by Blink>headerSnapshot-Content-Locationfor original URLquoted-printableencoding for HTML/CSS/JSbase64encoding for images and binary files- Proper
Content-ID: <xxx@mhtml.blink>format
Workflow
- User provides URL
- Run script:
python html_to_mhtml.py "<URL>" - Return path to created .mhtml file
Scan to join WeChat group