Saving a Web Page Into A Single File

你是否曾经想过要把一个包含图片和文本的网页保存到单个的文件里?你可以使用IE的 saveAs 功能,但是缺点很明显,这个Saveas 对话框总是出于安全考虑而被show up.有重复杂的做法,可以避开 SaveAs 对话框。下面我给大家示范如何操作:

Do you ever want to save a web page into one single file, including pictures and text? You can use IE SaveAs command, but the drawback is obvious, the Save As dialog is always shown up for security reason. There is a complicated work around to avoid the Save As dialog (see Automated IE SaveAs MHTML). Here I show you an easy way to do it:  

#import "c:/program files/common files/system/ado/msado15.dll" _
        no_namespace rename("EOF", "EndOfFile")
#import 
 
  no_namespace rename("EOF", "EndOfFile")

...

void SaveWholePage(LPCTSTR page_url,LPCTSTR save_filename)
{
   CoInitialize(NULL);
   {
      IMessagePtr       iMsg(__uuidof(Message));
      IConfigurationPtr iConf(__uuidof(Configuration));
      iMsg->Configuration = iConf;
      try
      {
         iMsg->CreateMHTMLBody(
            page_url,
            cdoSuppressNone,
            "domain//username",
            "password");
      }
      catch(_com_error err)
      {
         // handle exception
      }
      _StreamPtr pStream=iMsg->GetStream();
      pStream->SaveToFile( save_filename,
                           adSaveCreateOverWrite);
   }
   CoUninitialize();
}
简单的用法:
SaveWholePage("http://www.zaobao.com/gj/zg002_050203.html",
              "test.mht");

我们不提供例子程序,你可以把这段代码复制粘贴到你自己创建的程序中去。

Sample program is not provided, since you can create it on your own and copy & paste the above code snippet into your project.

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值