Consulting

Results 1 to 4 of 4

Thread: Getting data elements by Class VBA data scrapping

  1. #1
    VBAX Regular
    Joined
    Apr 2020
    Posts
    9
    Location

    Getting data elements by Class VBA data scrapping

    Dear VBA GURUS,

    I am trying to access to this website
    HTML Code:
    https://clinicaltrials.gov/ct2/show/NCT04134676
    and I want to collect a few elements using data scrapping techniques on VBA. I want to collect a few fields (please see image)

    VBA problem.jpg

    I am trying to run a code but this does not seem to be working and I really don't understand why. The error message I am getting is "Object variable or with block not set". The code is down below...Thank you once more for the help!

    Option Explicit
    
    Sub CountryPopList()
        Dim IE As InternetExplorer
        Dim htmlEle As IHTMLElement
        Dim i As Integer
       
          i = 1
       
         Set IE = New InternetExplorer
        IE.Visible = False
        IE.navigate "https://clinicaltrials.gov/ct2/show/NCT04134676"
       
           Application.Wait Now + TimeValue("00:00:05")
       
           For Each htmlEle In IE.document.getElementsByClassName("table.ct-data_table.tr-data_table")(0).getElementsByTagName("tr")
            With ActiveSheet
                .Range("A" & i).Value = htmlEle.Children(0).textContent
                .Range("B" & i).Value = htmlEle.Children(1).textContent
                .Range("C" & i).Value = htmlEle.Children(2).textContent
            
            End With
           
            i = i + 1
        Next htmlEle
       
    End Sub

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,443
    Location
    Sounds like you have the wrong class name.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Apr 2020
    Posts
    9
    Location
    Quote Originally Posted by xld View Post
    Sounds like you have the wrong class name.

    Hum I was pretty sure that the issue was not with the class name....it seems right to me

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,443
    Location
    I couldn't see that class name on the page, and I could get elements of a class ct-dim.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •