WebbrowserでのHTMLコンテンツの保存


WebbrowserでのHTMLコンテンツの保存
IPersistインタフェースを使用すると、HTMLをファイルに保存することができます.VBとDelphiでの実装は次のようになります.
VB: Dim oPF As IPersistFile Set oPF = WebBrowser1.Document oPF.Save "TheFileNameHere.htm", False
Delphi: 

uses
MSHTML,OleCtrls, SHDocVw, StdCtrls,ActiveX;
function GetHTMLCode(WB: IWebbrowser2; ACode: TStrings): Boolean;
var
ps: IPersistStreamInit;
s: string;
ss: TStringStream;
sa: IStream;
begin
ps := WB.document as IPersistStreamInit;
s := '';
ss := TStringStream.Create(s);
try
sa:= TStreamAdapter.Create(ss, soReference) as IStream;
Result := Succeeded(ps.Save(sa, Bool(True)));
if Result then ACode.Add(ss.Datastring);
finally
ss.Free;
end;
end;

VCの実現方法については、蒋晟のこの文章を参考にすることができる.
http://www.csdn.net/develop/read_article.asp?id=18465
さらにVB実装にはole_を参照する必要があるlib、このリファレンスはhttp://www.applevb.com/lib/tl_ole.zipでダウンロードされます.