save a web page as a single file (mht format) using Delphi code

Here‘s how to save a web page as a single file (mht format) using Delphi code:

uses CDO_TLB, ADODB_TLB;
...
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, cdoSuppressAll, ‘‘, ‘‘);
Stream := Msg.GetStream;
Stream.SaveToFile(FileName, adSaveCreateOverWrite);
finally
Msg := nil;
Conf := nil;
Stream := nil;
end;
end; (* WB_SaveAs_MHT *)

Sample usage:

//first navigate
WebBrowser1.Navigate(‘http://delphi.about.com‘);

//then save
WB_SaveAs_MHT(WebBrowser1,‘c:\WebBrowser1.mht‘);

Note 1: 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.
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.

资料引用:http://www.knowsky.com/336151.html

时间: 2024-08-01 00:15:12

save a web page as a single file (mht format) using Delphi code的相关文章

How to save content/text of a web page by forcing save-as option

I would like to know what would be the best way to save contents from a web page. I mean to force save-as option by clicking a link or button. I often found that javascript would not be an option because it's only working for IE, so I thought that it

Lesson 2 Building your first web page: Part 3

Time to build your first HTML page by hand I could go on with more theory and send half of you to sleep (trust me); instead you are now going to actually build your very first web page! One of the best ways to learn something is to actually do it, so

[Project] Simulate HTTP Post Request to obtain data from Web Page by using Python Scrapy Framework

1. Background Though it's always difficult to give child a perfect name, parent never give up trying. One of my friends met a problem now. his baby girl just came to the world, he want to make a perfect name for her. he found a web page, in which he

How a web page loads

The major web browsers load web pages in basically the same way. This process is known as parsing and is described by the HTML5 specification. A high-level understanding of this process is critical to writing web pages that load efficiently. Parsing

调试android chrome web page简明备忘

必备工具 adb tools.android chrome 先开启手机调试模式 adb forward tcp:9919 localabstract:chromedevtoolsremote 成功会提示 * daemon not running. starting it now on port 5037 * * daemon started successfully * 不成功的话用这个命令再试 adb kill-server 接着打开下面的链接,这里的9919是上面adb命令中指定的 http

LR实战之Discuz开源论坛——网页细分图结果分析(Web Page Diagnostics)

续LR实战之Discuz开源论坛项目,之前一直是创建虚拟用户脚本(Virtual User Generator)和场景(Controller),现在,终于到了LoadRunner性能测试结果分析(Analysis)这部分了. LoadRunner结果分析图表功能中最重要图表分析之一,就是网页诊断细分图,在Controller场景设计运行之前,需要在菜单栏中设置启用网页诊断功能(诊断-网页诊断-启动),如图: 网页细分图,是显示每个页面及其组件的相关下载时间和大小,主要用来评估页面内容是否影响事务

微信(WeChat web page)

插件介绍: 说到微信,相信身边的很多朋友都在使用这个软件,因为它有着很多强大的功能,包括朋友圈.摇一摇.漂流瓶.语音提示等,使之成为我们生活中很重要的部分,最初在手机上使用,后来也出现了网页版,今天为大家推荐这款网页版的微信插件. 使用说明: 将微信(WeChat web page)添加至chrome,并在应用中启动它. 功能介绍: -通讯录-朋友圈-发送文件-截图工具-桌面通知-公共账号 http://www.chrome001.com/谷歌插件大全长期为您更新.

解读Web Page Diagnostics网页细分图

http://blog.sina.com.cn/s/blog_62b8fc330100red5.html Web Page Diagnostics (以下简称WPD),这是LR Analysis中非常重要的一块,搞清楚这部分的内容会让你少走很多弯路,很多环境问题都可以通过它来定位,比如客户端,网络.通过它可以你可以比较好的来定位是环境的问题还是应用本身的问题,当然更重要的是Web页面本身的问题. Web Page Diagnostics:页面诊断图,也叫页面分解总图 “页面分解”显示某一具体事务

Lesson 2 Building your first web page: Part 2

Tag Diagram You may have noticed that HTML tags come in pairs; HTML has both an opening tag (<tag name>) and a closing tag (</tag name>). The only difference between the opening and closing tags is that the closing tag contains an extra forwar