保存网页MHT




uses ADODB_TLB, CDO_TLB, ComObj,MSHTML;
{$R *.dfm}
{能把网页如 WWW.QQ.COM保存为一个单文件 .MHT
但不能把一个 A.HTM 保存为一个单文件 .MHT

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, cdoSuppressNone, '', '');
    Stream := Msg.GetStream;
    Stream.SaveToFile(FileName, adSaveCreateOverWrite);
  finally
    Msg := nil;
    Conf := nil;
    Stream := nil;
  end;
end; (* WB_SaveAs_MHT *)

procedure TForm1.FormCreate(Sender: TObject);
var
  f: string;
begin
  f := ExtractFilePath(Application.ExeName) + 'WebDoc.htm';
  WebBrowser1.Navigate( 'file:///C:\Users\Admin\Desktop\新建文件夹\WebDoc.htm');
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  WB_SaveAs_MHT(WebBrowser1, 'C:\Users\Admin\Desktop\11.mht');
end;








附件列表

     

    你可能感兴趣的:(网页)