Board index » cppbuilder » How to save a certain web-adress-contents as .mht (web-archive, single file) as IE does?

How to save a certain web-adress-contents as .mht (web-archive, single file) as IE does?


2005-07-07 03:32:56 PM
cppbuilder73
How can I save a certain web-adress-contents as .mht (web-archive,
single file) as IE does?
Additionally I want to change the html-source-code, i.e. the original
source-code of this page should be replaced by an own.
Thanks a lot,
Michael
 
 

Re:How to save a certain web-adress-contents as .mht (web-archive, single file) as IE does?

<M_R>wrote in message news: XXXX@XXXXX.COM ...
Quote
How can I save a certain web-adress-contents as .mht
(web-archive, single file) as IE does?
You will have to download all of the relavant files manually and generate
the mht file yourself. There is no way to programmably tell IE to generate
a mht file for you. Which also means that you will have to parse the
downloaded HTML in order to know where all the dependant files (images,
sounds, etc) are located.
Gambit
 

Re:How to save a certain web-adress-contents as .mht (web-archive, single file) as IE does?

I looked around the internet and found some sources for VC, e.g. in
www.codeguru.com/Cpp/I-N/ieprogram/comments.php/c4397/
but unfortunately I failed in compiling this with BCB.
I started with
#import "c:\programme\gemeinsame dateien\system\ado\msado15.dll"
no_namespace raw_interfaces_only
#import "c:\windows\system32\cdosys.dll" no_namespace
raw_interfaces_only
#include "c:\language\cppbuilder.5\include\cdosysstr.h"
#include "c:\language\cppbuilder.5\include\cdosyserr.h"
and continued with
int SaveWholePage(AnsiString szPageURL, AnsiString szFileName) {
CoInitialize(NULL);
// BSTR bstr=szPageURL.AllocSysString();
WideString w_bstr=WideString(szPageURL); // ??? CORRECT
MODIFICATION?
BSTR bstr=w_bstr.c_bstr();
// CString szUserName="domain\\username";
// BSTR bstrUserName=szUserName.AllocSysString();
WideString w_bstrUserName="domain\\username";
BSTR bstrUserName=w_bstrUserName.c_bstr();
// CString szPass="domain\\username";
// BSTR bstrPass=szPass.AllocSysString();
WideString w_bstrPass="domain\\username";
BSTR bstrPass=w_bstrPass.c_bstr();
IMessage *pMsg=NULL;
IConfiguration* pConfig = NULL;
_Stream* pStm = NULL;
HRESULT hr=CoCreateInstance( __uuidof(Message), NULL,
CLSCTX_INPROC_SERVER, __uuidof(IMessage), (void**)&pMsg);
hr=CoCreateInstance(__uuidof(Configuration), NULL,
CLSCTX_INPROC_SERVER, __uuidof(IConfiguration), (void**)&pConfig);
/*
pMsg->put_Configuration(pConfig);
...
*/
}
Because I got an error saying Message/Configuration is unknown I
explicitely defined them before the function as
typedef IMessage Message;
typedef IConfiguration Configuration;
Because of some further compiler-errors (*) I temporarily commented
out the rest of the function testing the so-far compiled with the
de{*word*81}, just to find out both CoCreateInstance-function-calls
returned NULL, so something seems to go wrong.
Being totally unfamilar with COM I do not know how to continue...
(Perhaps my modification from CString to AnsiString in the function
call and the conversion to BSTR is not correct...)
Thanks a lot,
Michael
~~~~
(*) The following error says put_Configuration() is no element of
IMessage. Probably I would have to include cdo.h or cdosys.h, but
doing this I get additional compiler-errors telling me _ADO already
declared, ...
~~~~
Other resources I found (but did not succeed either)
www.codeguru.com/Cpp/I-N/ieprogram/article.php/c4397/
delphi.about.com/od/internetintranet/l/aa062904a.htm
www.cryer.co.uk/brian/delphi/twebbrowser/Save_as_MHT.htm
 

{smallsort}

Re:How to save a certain web-adress-contents as .mht (web-archive, single file) as IE does?

Why does it have to be in MHT format? If you are just looking for a way to
mirror a website, then there are plenty of website copying programs out there,
and some of them are free and excellent, for example, HTT copier (not sure of
the name or webpage it's on).
--
Mark Jacobs
www.dkcomputing.co.uk
 

Re:How to save a certain web-adress-contents as .mht (web-archive, single file) as IE does?

<M_R>wrote in message news: XXXX@XXXXX.COM ...
Quote
I looked around the internet and found some sources for VC, e.g. in

www.codeguru.com/Cpp/I-N/ieprogram/comments.php/c4397/

but unfortunately I failed in compiling this with BCB.
That is because that code is not very BCB-friendly.
Quote
#import "c:\programme\gemeinsame dateien\system\ado\msado15.dll"
no_namespace raw_interfaces_only
#import "c:\windows\system32\cdosys.dll" no_namespace
raw_interfaces_only
#import is discouraged in BCB. Use the TLIBIMP.EXE utility to import those
libraries instead.
Quote
#include "c:\language\cppbuilder.5\include\cdosysstr.h"
#include "c:\language\cppbuilder.5\include\cdosyserr.h"
You should not be specifying full paths for those files. BCB includes those
files in its own Includes folder, so you can do this instead:
#include <cdosysstr.h>
#include <cdosyserr.h>
Quote
and continued with
Your translation is not correct. Use this instead:
#include <cdosysstr.h>
#include <cdosyserr.h>
#include <cdoex.h>
#include <utilcls.h>
CLSID CLSID_Configuration = {0xCD000002, 0x8B95, 0x11D1, {0x82, 0xDB,
0x00, 0xC0, 0x4F, 0xB1, 0x62, 0x5D}};
CLSID CLSID_Message = {0xCD000001, 0x8B95, 0x11D1, {0x82, 0xDB, 0x00,
0xC0, 0x4F, 0xB1, 0x62, 0x5D}};
bool SaveWholePage(const AnsiString &PageURL, const AnsiString
&FileName)
{
bool ret = false;
CoInitialize(NULL);
TComInterface<IMessage>Msg;
TComInterface<IConfiguration>Config;
TComInterface<_Stream>Stream;
if( SUCCEEDED(CoCreateInstance(CLSID_Message, NULL,
CLSCTX_INPROC_SERVER, IID_IMessage, (void**)&Msg)) )
{
if( SUCCEEDED(CoCreateInstance(CLSID_Configuration, NULL,
CLSCTX_INPROC_SERVER, IID_IConfiguration, (void**)&Config)) )
{
Msg->put_Configuration(Config);
if( SUCCEEDED(Msg->CreateMHTMLBody(WideString(PageURL),
cdoSuppressNone, WideString("domain\\username"), WideString("password"))))
{
if( SUCCEEDED(Msg->GetStream(&Stream)) )
ret =
SUCCEEDED(Stream->SaveToFile(WideString(FileName), adSaveCreateOverWrite));
}
}
}
CoUninitialize();
return ret;
}
Quote
Because I got an error saying Message/Configuration is unknown
I explicitely defined them before the function as

typedef IMessage Message;
typedef IConfiguration Configuration;
That is not the correct thing to do.
Gambit