Function GetHTML() As String
Dim oPI As IPersistStreamInit
Dim oPM As IPersistMemory
Dim mem() As String
Dim cbSize As Long
Set oPI = IE.Document
oPI.Save oPM, False
cbSize = oPM.GetSizeMax
ReDim mem(cbSize)
MsgBox cbSize
oPM.Save mem(0), False, cbSize
Set oPM = Nothing
ReDim mem(0)
End Function上面这个代码出错,DELPHI版的我有Function GetHTML2() As String ''''这个可以正常使用
Dim oPF As IPersistFile
Set oPF = IE.Document
oPF.Save "c:\1.htm", False
Set oPF = Nothing
End Function上面这个可以,但是保存到文件了,我只想在内存中.....
Dim oPI As IPersistStreamInit
Dim oPM As IPersistMemory
Dim mem() As String
Dim cbSize As Long
Set oPI = IE.Document
oPI.Save oPM, False
cbSize = oPM.GetSizeMax
ReDim mem(cbSize)
MsgBox cbSize
oPM.Save mem(0), False, cbSize
Set oPM = Nothing
ReDim mem(0)
End Function上面这个代码出错,DELPHI版的我有Function GetHTML2() As String ''''这个可以正常使用
Dim oPF As IPersistFile
Set oPF = IE.Document
oPF.Save "c:\1.htm", False
Set oPF = Nothing
End Function上面这个可以,但是保存到文件了,我只想在内存中.....
GetHTML2 = IE.Document.body.innerHTML
End Function
你这个在NavigateComplete2事件中不行.
如果你一定要在跳转前得到目标URL的网页内容,可以用XMLHTTP对象来取得目标网站的内容,使用方法
在我的博客中有范例,你可以自己去看一下
function TIENotify.GetHTML:string;
var StrStream:TStringStream;
begin
StrStream:=TStringStream.Create('');
try
(FIEThis.Document as IPersistStreamInit).Save(TStreamadapter.Create(StrStream),false);
finally
Result:=StrStream.DataString ;
StrStream.Free ;
end;
end;procedure TIENotify.SetHTML(s:string);
var StrStream:TStringStream;
begin
StrStream:=TStringStream.Create(s);
try
(FIEThis.Document as IPersistStreamInit).Load(TStreamadapter.Create(StrStream));
finally
StrStream.Free ;
end;
end;
就像你的要求,要你的BHO对象在尚未读目标网页内容前取得目标网页的内容,这是不行的。只有通过其他途径去预取得目标网页内容。虽然能取得,但并不是说你的BHO对象已经按正常的工作方式转到了目标网页。当然要取得某个URL地址的内容的方法有很多,我所说的XMLHTTP只是使用系统对象实现这个目的的其中的一个方法,当然还有很多其他的方法。对于DELPHI的对象我不是很清楚,但相信不会逃出这种逻辑概念。
Dim oPF As IPersistFile
Set oPF = IE.Document
oPF.Save "c:\1.htm", False
Set oPF = Nothing
End Sub
void NavigateComplete2(
[in] IDispatch* pDisp,
[in] Variant * URL
);Fires after a navigation to a hyperlink is completed (on either a window or frameset element). Returns S_OK to indicate that the operation was successful.
pDisp
Address of the frame'sIDispatch interface.
URL
String expression that evaluates to the URL, UNC file name, or PIDL that was navigated to. Note that this URL can be different from the URL that the browser was told to navigate to. One reason is that this URL is the canonicalized and qualified URL; for example, if an application specified a URL of "www.microsoft.com" in a call to the Navigate or Navigate2 method, the URL passed by NavigateComplete2 would be "http://www.microsoft.com/". Also, if the server has redirected the browser to a different URL, the redirected URL will be reflected here.
The URL parameter can be a PIDL in the case of a shell namespace entity for which there is no URL representation. This event replaces the NavigateComplete and FrameNavigateComplete events, which should no longer be used. Internet Explorer 4.0 continues to fire the NavigateComplete and FrameNavigateComplete events for compatibility with Internet Explorer 3.0. 你只不过用的不是XMLHTTP对象来取得内容而已,用IPersistFile对象就不是我说的"很多其他的方法"了吗?
Dim oPF As IPersistFile
这个要引用什么东西才可以运行?