PDA

View Full Version : Getting data elements by Class VBA data scrapping



pedrosc
05-02-2020, 02:54 AM
Dear VBA GURUS,

I am trying to access to this website
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)

26546

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

Bob Phillips
05-02-2020, 05:47 AM
Sounds like you have the wrong class name.

pedrosc
05-02-2020, 06:06 AM
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 :think::think::think:

Bob Phillips
05-02-2020, 10:07 AM
I couldn't see that class name on the page, and I could get elements of a class ct-dim.