1

I am using below mentioned code in Excel VBA for IE navigation.I am facing following error while fetching data from iframe.

Error detail:

Object does not support this property or method


Option Explicit

Public Sub Cgg_Click()
    Dim Ie As New InternetExplorer
    Dim WebURL
    Dim Docx As HTMLDocument
    Dim productDesc
    Dim productTitle
    Dim price
    Dim RcdNum
    
    Ie.Visible = True
    WebURL = "https://www.google.com/maps/place/parlour+beauty+parlour+beauty/@40.7314166,-74.13182,11z/data=!4m8!1m2!2m1!1sParlour+NY!3m4!1s0x89c2599bd4c1d2e7:0x20873676f6334189!8m2!3d40.7314166!4d-73.9917443"
    Ie.Navigate2 WebURL
    
    Do Until Ie.readyState = READYSTATE_COMPLETE
        DoEvents
    Loop
    
    Application.Wait (Now + TimeValue("00:00:25"))
    
    For N = 0 To Ie.document.getElementsByClassName("section-subheader-header GLOBAL__gm2-subtitle-alt-1").Length - 1
                       
        If Ie.document.getElementsByClassName("section-subheader-header GLOBAL__gm2-subtitle-alt-1").Item(N).innerText = "Web results" Then
            Ie.document.getElementsByClassName("section-subheader-header GLOBAL__gm2-subtitle-alt-1").Item(N).ScrollIntoView (False)
        End If
                    
    Next N
    
    Application.Wait (Now + TimeValue("00:00:25"))
         
    Set Docx = Ie.document
    
    productDesc = Docx.Window.frames("section-iframe-iframe").contentWindow.document.getElementsByClassName("trex")(0).outerHTML

End Sub

Here is the HTML:

enter image description here


Please help to resolve this error.

I want to extract "trex" ClassName HTML Contain from above url

Thanks.

QHarr
  • 83,427
  • 12
  • 54
  • 101
Lalit Patel
  • 115
  • 14
  • Navigate directly to the src of the iframe – QHarr Feb 02 '21 at 12:03
  • Please use the snippet tool via [edit] to insert html rather than post pictures of html. We can't copy paste from that image. See [this](https://meta.stackexchange.com/a/22189/731568) for help or use see the formatting section of [help] . Navigating using src of iframe see: https://stackoverflow.com/questions/44902558/accessing-object-in-iframe-using-vba/55666947#55666947 – QHarr Feb 02 '21 at 12:08

1 Answers1

2

You can change the line of extract "trex" element to one of the following, both of them can work well:

  1. Use the getElementsbyTagName method to get the Iframe first , then according to the Iframe.contentDocument property to reach the element via the class name:

    productDesc = Docx.getElementsByTagName("iframe")(0).contentDocument.getElementsByClassName("trex")(0).outerHTML
    
  2. Use querySelector method to get the Iframe through class, then use the same as the above to reach the element:

    productDesc = Docx.querySelector(".section-iframe-iframe").contentDocument.getElementsByClassName("trex")(0).outerHTML
    
Yu Zhou
  • 11,532
  • 1
  • 8
  • 22