none
請教關於透過 SHDocVw.InternetExplorer 取得 Frame html code 問題 RRS feed

  • 一般討論

  • Dear all

     

    我常識要透過 SHDocVw.InternetExplorer 來控制 IE 取得一個 frame 網站的各個 frame 原始碼, 但是一直都無法順利取得

    我利用 DocumentCompleted 事件來取得 frame html code, 會一直發生 exception , 但是倘若我透過另外一個元件, ex button , 在 onclick 事件利用 SHDocVw.ShellWindows 來掃描全部的 IE 視窗就可以取得 frame html code , 請問為什麼 DocumentCompleted 事件發生時, 無法取得 frame html code 呢 ? 感激不盡

     

    Sample Code (DocumentCompleted 事件會有錯誤, OnClick 事件就可以)

     

                Dim SWs As New SHDocVw.ShellWindows
                Dim IE As SHDocVw.InternetExplorer
                Dim Doc As Object
                Dim ObjDoc As mshtml.HTMLDocument

                'Text1.Text  =  SWs.count
                Dim strlist1 As String = " "
                Dim strlist2 As String = " "
                Dim i As Integer = 0
                Dim j As Integer = 0
                Dim k As Integer = 0

                Dim flag As Boolean = False

               

                For Each IE In SWs

                    Doc = IE.Document
                    If TypeOf Doc Is mshtml.HTMLDocument Then

                        If (IE.HWND = WebBrowser.HWND) Then

                            ObjDoc = Doc
                            Debug.Print(ObjDoc.title)


                            Debug.Print(ObjDoc.body.innerHTML)
                            Debug.Print(ObjDoc.frames.length)
                            For k = 0 To ObjDoc.frames.length - 1
                                Debug.Print(ObjDoc.frames.item(k).document.body.innerHTML)

                            Next

                        End If

                    End If

                Next

    2008年8月6日 上午 03:56