Slashdot is powered by your submissions, so send in your scoop

 



Forgot your password?
typodupeerror
×
Microsoft

Extracting HTML and Images from MHT and CHM? 14

smoon asks: "I've got a boatload of .CHM files, and have recently run across some .MHT files. The .MHT format appears to be how MS Internet Explorer saves a web site for offline viewing, and appears to be a basic MIME-format with all images inlined as base64 encoded data. I've poked around a bit looking for a utility that will extract the HTML files and associated graphics so that I can view these in Linux, but no luck so far. The .CHM format is billed as a 'compiled' HTML, and boils down to the equivalent of a tarball, in some Microsoft proprietary format, that shows a series of web pages. MS has a .CHM developers kit that allows you to extract all of the data, but the links stop working and it ends up not being very useful. Anyone know of a code that can extract the HTML and associated images from .CHM or .MHT files?"
This discussion has been archived. No new comments can be posted.

Extracting HTML and Images from MHT and CHM?

Comments Filter:
  • Perl! (Score:3, Interesting)

    by Howie ( 4244 ) <howie@thi[ ].com ['ngy' in gap]> on Sunday January 27, 2002 @11:49AM (#2909620) Homepage Journal
    I've never tried it, but MIME::Tools [zeegee.com] should deal with .mht files, since they are (at first glance at least) valid MIME documents. Some assembly required.
  • CHM extractor. (Score:4, Informative)

    by kyz ( 225372 ) on Sunday January 27, 2002 @01:10PM (#2909843) Homepage
    First off, MHT is just a mime message, run mpack [debian.org] on it.

    However, for CHM extraction, you can use this portable CHM extractor [uklinux.net]. I don't think Matthew has officially released it, but it should be OK to use. Get in touch with him if you want.
  • by fm6 ( 162816 ) on Sunday January 27, 2002 @03:10PM (#2910235) Homepage Journal
    All the functionality for browsing CHM files is built into IE. Here's a typical URL:
    ms-its:C:\WINNT\Help\Gstart.chm::/whats_new_in_win dows_2000_server.htm
    You can get the URL for any given CHM page from its properties dialog, available from the right-click menu. Looks like a label, but it's really a read-only text box, so it's easy to copy.

    This opens up options for using IE to extract text and graphics. If you just need the odd item, go to the page in Help, copy the URL to IE, and use IE's Save features. Mass dumps are harder. You could probably do it programmatically, since IE is a COM Automation server. But there are differences in the way links work, and you'd have to figure those out.

    It's my understanding the CHM is built using something called the IStorage Interface [microsoft.com], but I'm vague on the specifics. There's some interesting Delphi software here [helpware.net] (look for the "CHM Explorer Demo"). This Usenet thread [google.com] is also intriguing.

    I have to take the excuse to bemoan the poor state of online Help engines. More and more documentation is moving online, yet nobody seems to be really working on it. JavaHelp looks promising [sun.com], but it doesn't seem to attract much interest outside the Java community. (Are the issues technical or political?) The KDE web site boasts of an "XML help system", but that just means they do their authoring in XML -- which is good, but the content is actually distributed as a large collection of HTML files, managed by a standard web indexer and a poorly integrated TOC manager. GNOME does something similar.

    Which means that HTML Help, despite its flaws and limitations, is actually the best widely-used Help Engine! A sad state of affairs.

    This isn't rocket science. All you need is a way to combine a lot of files into a resource archive (no sane product integrator wants to include thousands of separate text files in a product), an indexer, an outliner, and some basic UI engineering. But I don't see any real open-source effort at all. Come on, do you want people to use Linux on the desktop or not?

  • HTML Help Workshop (Score:2, Informative)

    by vukv ( 550649 )
    HTML Help Workshop from MS can perfectly extract all of the files in .chm, in their original state. Open it up, click on decompile and voila... I dont see how you managed to run into problems, i have done so with hundreds of chm files...sure, it doesnt always save all chm related data however files are always preserved in their original state
  • I am not a programmer, but this works for me. The "code", such as it is, was taken directly from the Perl MIME::Parser module man page. Install MIME::Tools first, and then make a script like:
    ---
    #!/usr/bin/perl
    use MIME::Parser;

    my $parser = new MIME::Parser;
    $parser->output_under("/tmp");
    $entity = $parser->parse(\*STDIN);
    ---

    (call it unmht.pl for this example).
    Make that script executable, and then just "cat yourmhtfile.mht | unmht.pl". The files contained within the mht should all end up in a directory under /tmp in this case. If you change "output_under" to "output_dir", it will dump them all directly in /tmp, or in whatever directory you specified there.

He has not acquired a fortune; the fortune has acquired him. -- Bion

Working...