Extracting Text from a Saved MHTML Page
How MHTML to TXT conversion works, what it keeps and drops, and when plain text from a saved web page is good enough for reading, search or reuse.
Is converting MHTML to plain text right for your use?
Converting MHTML to text is a good fit when you need the words of a saved page and not its appearance. The main benefit is a small, universally readable file that is easy to search, quote, diff, index or feed into other tools. The decisive tradeoff is that structure goes away: headings, link targets, table layout, images and anything the page expressed through styling are flattened or dropped. If those carry meaning for your task, keep the MHTML file or convert it to HTML or Markdown instead of plain text.
- Plain text is usually the better choice for: full-text search across an archive of saved pages
- Quoting or excerpting article prose
- Comparing two saved versions of the same page line by line
- Passing page content to scripts, translation tools or text analysis
- Reading on devices or in editors that cannot open MHTML
- Plain text is a poor choice for: pages where tables, forms or code layout matter
- Pages whose value lies in their links or the addresses they point to
- Documents that must stay visually faithful for legal or evidential purposes
- Content that mixes right-to-left and left-to-right text in complex ways
What the conversion actually changes
An MHTML file (often saved with the .mhtml or .mht extension, for example by Chromium-based browsers' single-file save option) is a MIME message, the same container format used for email. It bundles the page's HTML together with its images, stylesheets and sometimes frames as separate parts. Each part has headers stating its content type, its character set and how it was encoded for transport, typically quoted-printable or base64. The original page address is usually recorded in a Content-Location header.
Getting text out involves three distinct steps, and errors in any one of them show up in the result: decoding the transport encoding, decoding bytes into characters using the declared character set, and stripping the HTML down to its text content.
| Layer | What happens | Typical failure |
| MIME container | The main text/html part is located among the bundled resources | Picking the wrong part, or missing text that lives in a separate frame part |
| Transfer encoding | Quoted-printable or base64 is decoded back into raw bytes | Leftover =3D sequences or words split by soft line breaks |
| Character set | Bytes are interpreted as characters using the declared charset | Garbled text (mojibake), common with Cyrillic pages saved in legacy encodings such as windows-1251 or KOI8-R |
| HTML to text | Tags are removed, entities such as & are decoded, scripts and styles are discarded | Script code or CSS appearing in the output, or all text running together without line breaks |
The following illustrative fragment shows what a quoted-printable HTML part looks like and what it should become. The sequence =3D stands for an equals sign, =C3=A9 is the UTF-8 encoding of é, and an equals sign at the end of a line is a soft line break that joins the two lines.
Raw part inside the .mhtml file:
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
<p class=3D"note">Caf=C3=A9 hours chang=
ed today.</p>
<p>=D0=9F=D1=80=D0=B8=D0=B2=D0=B5=D1=82</p>
After decoding:
<p class="note">Café hours changed today.</p>
<p>Привет</p>
Extracted text:
Café hours changed today.
Привет
Despite sharing a category with tools that reverse, mirror or restyle text, this conversion does none of those things. It does not change the order of characters or words, does not substitute look-alike Unicode characters, and does not add mirrored glyphs. When it works correctly, the stored characters in the output are the same characters the page contained, so combining accents and multi-code-point emoji survive intact. What it removes is presentation: fonts, colors, CSS layout, visual ordering and the HTML attributes that controlled how text was displayed. The distinction matters because text that looked a certain way on screen may have been stored differently in the HTML, and plain text keeps only the stored version.
A minimal local extraction sketch
For readers comfortable with a script, Python's standard library can handle all three layers without uploading the file anywhere. The sketch below is illustrative and has not been tested here against files from specific browsers. It takes only the first HTML part, skips script and style content, and inserts line breaks at common block elements; it does not collapse extra whitespace or preserve link addresses.
import email
from email import policy
from html.parser import HTMLParser
class TextCollector(HTMLParser):
SKIP = {'script', 'style', 'noscript', 'template'}
BLOCK = {'p', 'div', 'li', 'br', 'tr', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'}
def __init__(self):
super().__init__()
self.parts = []
self.skip_depth = 0
def handle_starttag(self, tag, attrs):
if tag in self.SKIP:
self.skip_depth += 1
elif tag in self.BLOCK:
self.parts.append('\n')
def handle_endtag(self, tag):
if tag in self.SKIP and self.skip_depth:
self.skip_depth -= 1
def handle_data(self, data):
if not self.skip_depth:
self.parts.append(data)
with open('page.mhtml', 'rb') as f:
msg = email.message_from_binary_file(f, policy=policy.default)
text = ''
for part in msg.walk():
if part.get_content_type() == 'text/html':
# get_content() undoes the transfer encoding and applies the charset
collector = TextCollector()
collector.feed(part.get_content())
text = ''.join(collector.parts)
break
with open('page.txt', 'w', encoding='utf-8') as out:
out.write(text)
Writing the output as UTF-8 avoids a second round of encoding problems, which matters for pages in Russian or any other non-Latin script. If a part declares no charset or the wrong one, decoding can fail or produce garbled text, and the declared value may need to be overridden after checking the page's own meta charset tag.
Will the text stay readable and usable after copying or sharing?
Plain text is the most portable format there is, so the resulting file will open and paste almost anywhere. The usability questions come from what the conversion discarded, not from compatibility.
Reading order follows the order of elements in the HTML source, not the order they appeared on screen. Pages that rearrange content with CSS layout, sidebars, sticky headers or absolutely positioned elements can produce text where navigation menus, cookie notices or related-article blocks sit between paragraphs of the main content. Because no stylesheet is applied during simple extraction, text the page hid from view, such as collapsed menus or content for other screen sizes, may also appear in the output.
Links lose their targets. The visible link text remains, but the address behind it is gone unless the extraction tool is set to keep it, for example by writing the address in brackets after the link text. If your goal is to recover the web addresses a page referenced, plain-text extraction of the visible content is the wrong operation; you need a tool that reads the href attributes, and possibly the Content-Location headers of the bundled parts.
Right-to-left text such as Arabic or Hebrew is stored in logical order, so the characters themselves are preserved. However, the HTML dir attribute and CSS direction settings are lost, and a plain-text viewer will fall back on the Unicode bidirectional algorithm alone. Paragraphs that mix directions, especially with numbers or punctuation at the edges, may display in a different order than they did on the page even though the stored text is unchanged.
For assistive technology, plain text generally reads as a continuous stream, which is serviceable for prose. What disappears is the semantic structure screen reader users rely on to navigate: heading levels, list boundaries, table headers and image alternative text (unless the extractor deliberately keeps alt attributes). No screen reader was tested for this review, so claims about how a specific one handles a given output would need their own check. Where navigation by structure matters, an HTML or Markdown export is the more accessible choice.
For search and editing, plain text is an advantage: every word is directly searchable and editable without markup getting in the way. The cost is that editing cannot restore lost structure, so treat the text file as a derived copy and keep the original MHTML if you may need the formatted version later.
Privacy when choosing a converter
A saved MHTML file can contain more than the visible article, including content from a logged-in session, embedded form values or tracking parameters in recorded addresses. Online converters require uploading that file, and a tool's appearance or marketing wording says nothing reliable about how it stores or uses uploads. For pages saved while signed in, or for anything confidential, local conversion with a script or an offline tool avoids the question entirely.
Gaps in this review
- No specific MHTML-to-text converters were tested, so no tool is rated or recommended by name
- The Python sketch is illustrative and was not run against files saved by particular browser versions
- No measurements of accuracy, speed or file size were made
- Behavior with specific screen readers, editors or sharing destinations was not verified
- Handling of pages with frames, shadow DOM content or script-generated text depends on how the browser saved the page and was not examined