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') ;

相关阅读 >>

Delphi 获取与设置系统环境变量

Delphi 保证当前程序显示在最前

Delphi 10.4.1的编译器bug终于修正了!

delpni-xe5-android sdk api 层次结构

Delphi controlcount和componentcount的区别

Delphi文本文件读与写

Delphi hmacsha256

Delphi 无法调用cmd nbtstat命令解决办法

Delphi xe5 android应用程序获取电池信息

Delphi 判断字符串是否为纯字母组合

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...

    正在狠努力加载,请稍候...