利用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;
|