When working with Delphi, the TWebBrowser component allows you to create a customized Web browsing application or to add Internet, file and network browsing, document viewing, and data downloading capabilities to your applications.

与Delphi一起使用时, TWebBrowser组件使您可以创建自定义的Web浏览应用程序,或为应用程序添加Internet,文件和网络浏览,文档查看和数据下载功能。

如何从TWebBrowser保存网页 ( How to Save a Web Page from TWebBrowser )

When using Internet Explorer, you are allowed you to view the source HTML code of a page and to save that page as a file on your local drive. If you are viewing a page that you wish to keep, go to the File/Save As ... menu item. In the dialog box that opens, you have several file types offered. Saving the page as a different filetype will affect how the page is saved.

使用Internet Explorer时,可以查看页面的源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 an HTML file to a disk.

TWebBrowser组件(位于组件面板的“ Internet”页面上)使您可以从Delphi应用程序访问Web浏览器功能。 通常,您需要启用将WebBrowser内显示的网页作为HTML文件保存到磁盘的功能。

将网页另存为原始HTML ( 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.

如果只想将网页另存为原始HTML,则可以选择“网页,仅HTML(* .htm,* .html)”。 它将简单地将当前页面的源HTML保存到驱动器中。 此操作不会保存该页面中的图形或该页面中使用的任何其他文件,这意味着,如果从本地磁盘重新加载文件,则会看到损坏的图像链接。

Here's how to save a web page as raw HTML using Delphi code:


Usage sample:


笔记 ( Notes)

  • The IPersistStreamInit and IStream interfaces are declared inside the ActiveX unit.

  • The web page is saved as a raw HTML to the WebBrowser1.html file on the root folder of the C drive.


MHT:Web存档,单个文件 ( MHT: Web Archive, Single File )

When you save a Web page as "Web archive, single file (*.mht)" the web document gets saved in the Multipurpose Internet Mail Extension HTML (MHTML) format with a .mht file extension. All relative links in the Web page are remapped and the embedded content is included in the .mht file, rather than being saved in a separate folder (as the case is with "Web Page, complete (*.htm, *.html)").

当您将网页另存为“ Web存档,单个文件(* .mht)”时,Web文档将以多用途Internet邮件扩展HTML(MHTML)格式保存,扩展名为.mht。 网页中的所有相对链接都被重新映射,并且嵌入的内容包含在.mht文件中,而不是保存在单独的文件夹中(视情况而定,“网页,完整(* .htm,* .html)”) )。

MHTML enables you to send and receive Web pages and other HTML documents using e-mail programs such as Microsoft Outlook, and Microsoft Outlook Express; or even your custom Delphi email sending solutions. MHTML enables you to embed images directly into the body of your e-mail messages rather than attaching them to the message.

MHTML使您能够使用电子邮件程序(例如Microsoft Outlook和Microsoft Outlook Express)发送和接收Web页和其他HTML文档。 甚至您的自定义Delphi电子邮件发送解决方案。 MHTML使您可以将图像直接嵌入到电子邮件正文中,而不是将其附加到邮件中。

Here's how to save a webpage as a single file (MHT format) using Delphi code:


Sample usage:


注意 ( Note)

  • The _Stream class is defined in ADODB_TLB unit that you probably already have created. The IMessage and IConfiguration interfaces code from cdosys.dll library. CDO stands for Collaboration Data Objects - object libraries designed to enable SMTP Messaging.

    _Stream类在您可能已经创建的ADODB_TLB单元中定义。 IMessage和IConfiguration接口代码来自cdosys.dll库。 CDO代表协作数据对象-旨在启用SMTP消息传递的对象库。

The CDO_TLB is an auto-generated unit by Delphi. To create it, from the main menu select "Import Type Library", select "C:\WINDOWS\system32\cdosys.dll" then click the "Create unit" button.

CDO_TLB是Delphi自动生成的单元。 要创建它,请从主菜单中选择“导入类型库”,选择“ C:\ WINDOWS \ system32 \ cdosys.dll”,然后单击“创建单元”按钮。

没有TWebBrowser ( No TWebBrowser )

You could rewrite the WB_SaveAs_MHT procedure to accept an URL string (not TWebBrowser) to be able to save a web page directly -- no need to use the WebBrowser component. The URL from WebBrowser is retrieved using the WB.LocationURL property.

您可以重写WB_SaveAs_MHT过程以接受URL字符串(而不是TWebBrowser)以能够直接保存网页-无需使用WebBrowser组件。 使用WB.LocationURL属性检索来自WebBrowser的URL。



  • 0
  • 2
  • 0


  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
©️2022 CSDN 皮肤主题:编程工作室 设计师:CSDN官方博客 返回首页
钱包余额 0