关于网友提出的“ 请问如何保持网页?”问题疑问,本网通过在网上对“ 请问如何保持网页?”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:
问题: 请问如何保持网页?
描述: 就是类似于IE里面的另存为功能,我想在delphi里面实现自动 对指定网址的html保存到本机,请问怎么实现呢?有没有代码学习一下,谢谢!
解决方案1: 我也没有delphi的,试试这个,vb的,也挺简单:
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的内容保存到文本就行了
解决方案2: http://expert.csdn.net/Expert/FAQ/FAQ_Index.asp?id=190155
在搜索中找到以下几种实现的方法。
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);
但是如果遇到人家网页里加上代码:
//禁止保存网页内容
则无法保存网页。
========================
请问谁能有更好的办法将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 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, '', '');
以上介绍了“ 请问如何保持网页?”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/3739842.html