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上面这个可以,但是保存到文件了,我只想在内存中.....

解决方案 »

  1.   

    Function GetHTML2() As String
       GetHTML2 = IE.Document.body.innerHTML
    End Function
      

  2.   


    你这个在NavigateComplete2事件中不行.
      

  3.   

    你要在 DocumentComplete 事件中处理就可以
      

  4.   

    DocumentComplete事件中是可以我知道我是想要在NavigateComplete2事件中保存与载入HTML源码
      

  5.   

    NavigateComplete2 是尚未执行网页跳转前的事件,既然尚未跳转,当然没有那个网页的内容信息啦。
    如果你一定要在跳转前得到目标URL的网页内容,可以用XMLHTTP对象来取得目标网站的内容,使用方法
    在我的博客中有范例,你可以自己去看一下
      

  6.   

    谢谢,我只是想知道VB是怎么用IPersistStreamInit来加载和保存IE.Document数据流的。这是DELPHI版的,可以在NavigateComplete2事件(浏览器未显示网页时)中存取HTML的数据
    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;
      

  7.   

    一个很简单的逻辑问题,比如有人叫你写一篇文章,但是你根本就没开始动笔写,这时候怎么可能存在你写的这篇文章在世界上呢?当然,这时候你从别人那买来一篇文章说是你的,当然也没问题,但这的确不是你自己所写的那篇文章呀。
    就像你的要求,要你的BHO对象在尚未读目标网页内容前取得目标网页的内容,这是不行的。只有通过其他途径去预取得目标网页内容。虽然能取得,但并不是说你的BHO对象已经按正常的工作方式转到了目标网页。当然要取得某个URL地址的内容的方法有很多,我所说的XMLHTTP只是使用系统对象实现这个目的的其中的一个方法,当然还有很多其他的方法。对于DELPHI的对象我不是很清楚,但相信不会逃出这种逻辑概念。
      

  8.   

    呵,你要这么说我也无语。实践才有发言权。你试一下以下的代码,保存在1.htm中的是什么就知道了。Private Sub IE_NavigateComplete2(ByVal pDisp As Object, URL As Variant)
        Dim oPF As IPersistFile
        Set oPF = IE.Document
        oPF.Save "c:\1.htm", False
        Set oPF = Nothing
    End Sub
      

  9.   

    我才无语呢,你先看看MSDN吧
    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对象就不是我说的"很多其他的方法"了吗?
      

  10.   

    各位,麻烦打断一下,问个问题
     Dim oPF As IPersistFile
    这个要引用什么东西才可以运行?
      

  11.   

    很多人问这个,其实那段delphi程序本身就有问题。