Save Web pages as HTML and MHT files by using the Twebbrowser component

Source: Internet
Author: User

one, save as HTML file

Uses ActiveX;
...
Procedure wb_saveas_html (wb:twebbrowser; const filename:string);
Var
Persiststream:ipersiststreaminit;
Stream:istream;
Filestream:tfilestream;
Begin
If not Assigned (WB. Document) Then
Begin
ShowMessage (' Document not loaded! ');
Exit;
End

Persiststream: = WB. Document as IPersistStreamInit;
FileStream: = Tfilestream.create (FileName, fmcreate);
Try
Stream: = Tstreamadapter.create (FileStream, soreference) as IStream;
If Failed (Persiststream.save (Stream, True)) then ShowMessage (' SaveAs HTML fail! ');
Finally
Filestream.free;
End
End (* wb_saveas_html *)

How to use:

WebBrowser1.Navigate (' http://www.uufax.com ');

Then save
Wb_saveas_html (WebBrowser1, ' c:/webbrowser1.html ');

Second, save as MHT single file

Uses cdo_tlb, adodb_tlb;
...
Procedure wb_saveas_mht (Wb:twebbrowser; Filename:tfilename);
Var
Msg:imessage;
Conf:iconfiguration;
Stream: _stream;
url:widestring;
Begin
If not Assigned (WB. Document) then Exit;

URL: = WB. Locationurl;

MSG: = comessage.create;
Conf: = coconfiguration.create;
Try
Msg.configuration: = Conf;
Msg.createmhtmlbody (URL, Cdosuppressall, ",");
Stream: = Msg.getstream;
Stream.savetofile (FileName, adsavecreateoverwrite);
Finally
MSG: = nil;
Conf: = nil;
Stream: = nil;
End
End (* wb_saveas_mht *)

How to use:

First Navigate
WebBrowser1.Navigate (' http://www.uufax.com ');

Then save
WB_SAVEAS_MHT (WebBrowser1, ' c:/webbrowser1.mht ');


This article from Csdn Blog, reproduced please indicate the source: http://blog.csdn.net/sunstone/archive/2009/11/09/4788743.aspx

Save Web pages as HTML and MHT files by using the Twebbrowser component

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.