TimvMechelen
Board Regular
- Joined
- Nov 7, 2016
- Messages
- 121
Hi all,
I have a code for getting data from a specific website. But when I run it I get an error (Compile Error: User-Defined Type Not Defined) at "Dim html As New HTMLDocument"
Can somebody please help me with this problem?
I have a code for getting data from a specific website. But when I run it I get an error (Compile Error: User-Defined Type Not Defined) at "Dim html As New HTMLDocument"
Can somebody please help me with this problem?
Code:
Sub Get_Web_Data()
Dim request As Object
Dim response As String
Dim html As New HTMLDocument
Dim website As String
Dim Followers As Variant
' Website to go to.
website = "https://soundcloud.com/timvanmechelen"
' Create the object that will make the webpage request.
Set request = CreateObject("MSXML2.XMLHTTP")
' Where to go and how to go there - probably don't need to change this.
request.Open "GET", website, False
' Get fresh data.
request.setRequestHeader "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT"
' Send the request for the webpage.
request.send
' Get the webpage response data into a variable.
response = StrConv(request.responseBody, vbUnicode)
' Put the webpage into an html object to make data references easier.
html.body.innerHTML = response
' Get the followers from the specified element on the page.
Followers = html.getElementsByClassName("infoStats__value sc-font-tabular-light").Item(0).innerText
' Output the followers into a cell.
Sheets("Sheet1").Range("A1").Value = Followers
End Sub