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