delphi 字符串保存html文件,Delphi WebBrowser1 保存文档为 .HTML

保存文档为 .HTML

The TWebBrowser component (located on the "Internet" page of the Component Palette) provides access to the Web browser functionality from your Delphi applications. In general, you'll want to enable saving of a web page displayed inside a WebBrowser as a HTML file to a disk.

Saving a web page as a raw HTML

If you only want to save a web page as a raw HTML you would select "Web Page, HTML only (*.htm, *.html)". It will simply save the current page's source HTML to your drive intact. This action will NOT save the graphics from the page or any other files used within the page, which means that if you loaded the file back from the local disk, you would see broken image links.

复制代码

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 *)

Usage sample:

//first navigate

WebBrowser1.Navigate('about:blank') ;

//then save

WB_SaveAs_HTML(WebBrowser1,'c:\WebBrowser1.html') ;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值