我用WebBrowser控件打开了一个框架页面index.htm 框架里有两个子页面,可WebBrowser.Document.Body.InnerHTML的内容是框架的HTML内容。请问该如何读取到框架里子页面里的内容呢?

解决方案 »

  1.   

    方法:
    1、找到网页文档对象。
    2、找到框架
    3、找到控件对象。
    4、读取数据Public Sub PreadNumAdd()
        On Error Resume Next
        Dim ShellWindow As ShellWindows
        Dim nCount As Integer
        Dim browser
        Dim Frame As Object
        Dim cFrame As Object
        Dim spDisp As Object
        Dim i As Integer
        Dim j, k
        Dim nil
        Dim Pcall As String
        Dim RegAdd As String
        Dim RegRoom As String
        Dim FrameCount As Integer
        Dim cFrameCount As Integer
        Dim hwnd As Long    Set ShellWindow = New ShellWindows           '读取登记号码
        nCount = ShellWindow.Count    For i = 0 To nCount - 1        Set spDisp = ShellWindow.Item(i)
            If spDisp = nil Then Exit Sub        If spDisp = "Microsoft Internet Explorer" Then               'IE浏览器
                hwnd = FindWindow(vbNullString, "我的网页 - Microsoft Internet Explorer")
                If hwnd = spDisp.hwnd Then
                    If spDisp.Document.Title = "我的网页" Then
                        FrameCount = spDisp.Document.frames.length - 1
                        For j = 0 To FrameCount
                            If spDisp.Document.frames(j).Name = "right_page" Then
                                Set Frame = spDisp.Document.frames(j)
                                cFrameCount = Frame.Document.frames.length - 1
                                If cFrameCount < 0 Then
                                    Pcall = Frame.Document.body.All("contact_phone").Value
                                    GoTo Continue
                                End If
                                For k = 0 To cFrameCount
                                    If (Frame.Document.frames(k).Name = "header") Then
                                        Set cFrame = Frame.Document.frames(k)                                    If cFrame.Document.Title = "网页Title-1" Or cFrame.Document.Title = "网页Title-2" Then
                                            Pcall = cFrame.Document.body.All("phone_number").Value
                                        Else
                                            Pcall = cFrame.Document.body.All("in_net_name").Value
                                        End If                                    Exit For  'exit k loop
                                    End If
                                Next k                            'Exit For 'exit j loop
                            Else
                                If spDisp.Document.frames(j).Name = "top_page" Then
                                    Set Frame = spDisp.Document.frames(j)
                                    RegAdd = Frame.Document.body.All("T3").Value
                                    RegRoom = Frame.Document.body.All("T2").Value
                                End If                        End If
                        Next j                End If
                End If        Else
                If spDisp = "Microsoft Web 浏览器控件" Then              '其他IE内核浏览器
                    FrameCount = spDisp.Document.frames.length - 1
                    For j = 0 To FrameCount
                        If spDisp.Document.frames(j).Name = "right_page" Then
                            Set Frame = spDisp.Document.frames(j)
                            cFrameCount = Frame.Document.frames.length - 1
                            If cFrameCount < 0 Then
                                Pcall = Frame.Document.body.All("contact_phone").Value
                                GoTo QuitSub
                            End If
                            For k = 0 To cFrameCount
                                If (Frame.Document.frames(k).Name = "header") Then
                                    Set cFrame = Frame.Document.frames(k)                                If cFrame.Document.Title = "网页Title-1" Or cFrame.Document.Title = "网页Title-2" Then
                                        Pcall = cFrame.Document.body.All("phone_number").Value
                                    Else
                                        Pcall = cFrame.Document.body.All("in_net_name").Value
                                    End If                                Exit For  'exit k loop
                                End If
                            Next k                        Exit For 'exit j loop
                        Else
                            If spDisp.Document.frames(j).Name = "top_page" Then
                                Set Frame = spDisp.Document.frames(j)
                                RegAdd = Frame.Document.body.All("T3").Value
                                RegRoom = Frame.Document.body.All("T2").Value
                                GoTo QuitSub
                            End If                    End If
                    Next j
                End If        End IfContinue:
            Err.Clear
            If i >= 32 Then
                GoTo QuitSub
            End If    Next i      'For i = 0 To nCount - 1
        'Resume Next
    QuitSub:
        PcallnumIN.Text = Pcall
        If RegAdd <> "" And RegRoom <> "" Then
            PregAddIN.Text = RegAdd & ":" & RegRoom
        End If
        Set ShellWindow = Nothing
        Set spDisp = Nothing
        Set Frame = Nothing
        Set cFrame = NothingEnd Sub
    以上是我的源码,你看这修改吧,这里面可能有些你不用的。