就是类似于IE里面的另存为功能,我想在delphi里面实现自动 对指定网址的html保存到本机,请问怎么实现呢?有没有代码学习一下,谢谢!
解决方案 »
- adoquery查询错误,请各位帮忙。谢谢
- 关于DBGrideh结果集复制,拷贝到Excel的问题。在线等。
- 我想编个小程序,各位给我引引路:)
- 季前辈,拦截pagecontrol边框的信息,该写在什么地方?
- overload类型的函数到底是降低编译速度还是执行速度?
- 怎样让我的程序开机后自动运行(最好有代码)
- indy客户端控件是否支持多线程?
- 问:请讲解Owner 和 Parent的详细区别,老达摩 和 nofog 有空也来说说
- c/s中用socket连接,有时会出没有磁盘空间的问题,提示是对某一个临时文件,请高手帮助
- 用delphi 的tquery 控件可以执行sql server 生成的sql文件吗?
- 问一个弱弱的问题,程序的图标大家一般是怎么找到的?
- 如何在DBGrid中响应OnMouseDown事件?
在搜索中找到以下几种实现的方法。
1.来自ZSWang的
http://expert.csdn.net/Expert/topic/2634/2634699.xml?temp=.6191217
它解决了将图片的路径修正为全路径,但仍未能将图片打包到mht文件中。
2.来自 oracle_lover(数据库情人)
http://expert.csdn.net/Expert/topic/2411/2411849.xml?temp=.5925714
代码如下:
var
tmpStrs: TStrings;
begin
tmpStrs:=TStringList.Create;
try
tmpStrs.LoadFromFile('C:\go.htm');
tmpStrs.SaveToFile('C:\go.mht');
finally
tmpStrs.Free;
end;
end;
根本就没有解决图片打包的问题。
3.在D6,D7利用WebBrowser控件进行转化
即webbrowser1.ExecWB(OLECMDID_SAVEAS, OLECMDEXECOPT_DONTPROMPTUSER);
但是如果遇到人家网页里加上代码:
//禁止保存网页内容
<noscript>
<iframe src="*.htm">
</iframe>
</noscript>
则无法保存网页。
========================
请问谁能有更好的办法将htm另存为mht文件,将图片打包进mht文件,并没有WebBrower控件下。
VC的代码,将就看吧
回复人: masterz(MS MVP) ( ) 信誉:147 2002-6-7 17:42:45 得分:300
#import "c:\program files\common files\system\ado\msado15.dll" no_namespace rename("EOF", "EndOfFile")
#import <cdosys.dll> no_namespace rename("EOF", "EndOfFile")
............
void CSavemhtDlg::OnOK()
{
// save url as a single file, in fact I don't know if it is mht file, but it can be opened by IE, can someone tell me?
CoInitialize(NULL);
{
IMessagePtr iMsg(__uuidof(Message));
IConfigurationPtr iConf(__uuidof(Configuration));
iMsg->Configuration = iConf;
try
{
iMsg->CreateMHTMLBody(
"http://example.microsoft.com",
cdoSuppressNone,
"domain\\username",
"password");
}
catch(_com_error err)
{
// handle exception
}
_StreamPtr pStream=iMsg->GetStream();
pStream->SaveToFile("test.mht",adSaveCreateOverWrite);
}
CoUninitialize();
}
谢谢 jiangsheng(蒋晟.MSMVP2004Jan)
原来是将cdoSuppressAll改为cdoSuppressNone就OK了,偶就是笨,试过cdoSuppressImages,就没有试其他了,看来下次要多试 哈哈
vMessage.CreateMHTMLBody(mURL, cdoSuppressNone, '', '');
procedure SaveWholePage(mURL: string; mFileName: TFileName);
var
vMessage: IMessage;
vConfiguration: IConfiguration;
vStream: _Stream;
begin
vMessage := CreateComObject(CLASS_Message) as IMessage;
vConfiguration := CreateComObject(CLASS_Configuration) as IConfiguration;
try
vMessage.Configuration := vConfiguration;
vMessage.CreateMHTMLBody(mURL, cdoSuppressNone, '', ''); //此用将zswang的cdoSuppressAll改为cdoSuppressNone
vStream := vMessage.GetStream;
vStream.SaveToFile(mFileName, adSaveCreateOverWrite);
finally
vMessage := nil;
vConfiguration := nil;
vStream := nil;
end;
end;
get/save the HTML Code from a TWebbrowser?
uses
ActiveX; function WB_SaveHTMLCode(WebBrowser: TWebBrowser; const FileName: TFileName): Boolean;
var
ps: IPersistStreamInit;
fs: TFileStream;
sa: IStream;
begin
ps := WebBrowser.Document as IPersistStreamInit;
fs := TFileStream.Create(FileName, fmCreate);
try
sa := TStreamAdapter.Create(fs, soReference) as IStream;
Result := Succeeded(ps.Save(sa, True));
finally
fs.Free;
end;
end; function WB_GetHTMLCode(WebBrowser: TWebBrowser; ACode: TStrings): Boolean;
var
ps: IPersistStreamInit;
ss: TStringStream;
sa: IStream;
s: string;
begin
ps := WebBrowser.Document as IPersistStreamInit;
s := '';
ss := TStringStream.Create(s);
try
sa := TStreamAdapter.Create(ss, soReference) as IStream;
Result := Succeeded(ps.Save(sa, True));
if Result then ACode.Add(ss.Datastring);
finally
ss.Free;
end;
end; procedure TForm1.Button1Click(Sender: TObject);
begin
WB_SaveHTMLCode(Webbrowser1, 'c:\test.txt');
end; procedure TForm1.Button2Click(Sender: TObject);
begin
WB_GetHTMLCode(Webbrowser1, Memo1.Lines);
end;
Private Sub Command1_Click()
WebBrowser1.Navigate "http://localhost/"
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Dim doc, objhtml As Object
Dim i As Integer
Dim strhtml As String
If Not WebBrowser1.Busy Then
Set doc = WebBrowser1.Document
i = 0
Set objhtml = doc.body.createtextrange()
If Not IsNull(objhtml) Then
Text1.Text = objhtml.htmltext
End If
Timer1.Enabled = False
End If
End Sub 只要把Text1.Text的内容保存到文本就行了
後面就是delphi胡代碼啊
我也有貼出鏈接啊