(Solved) – How would I grab data from a website that is in <span style in VBA?


I am a novice at VBA and HTML so any help is appreciated. I am trying to obtain data from a website, however, it is tagged under span style=”position: relative; white-space: nowrap;”>Data1. I have seen tutorials and examples all over the internet grabbing from span class but I am not sure how to do it for span style. The below is code I used from a youtube video that helped teach me how to do it for span class. The error message I get returned is: Run-time error ’91’; Object variable or With Block variable not set OR there is a textbook returning absolutely nothing. An image of the line I’m trying to obtain data from: Pc1

    Sub Get_Web_Data()

    Dim request As Object
    Dim response As String
    Dim html As New HTMLDocument
    Dim website As String
    Dim price As Variant

    website = "website1"

    Set request = CreateObject("MSXML2.XMLHTTP")

    request.Open "GET", website1, False

    'request.setRequestHeader "If-Modified-Since", "Sat 1 Jan 2000 00:00:00 GMT"


    response = StrConv(request.responseBody, vbUnicode)

    html.body.innerHTML = response

    price = html.getElementsByClassName("position: relative; max-width: 728px; width: 100%; margin-left: 10px; margin-right: 10px;")(0).innerText

    MsgBox price

Leave a Reply

Your email address will not be published. Required fields are marked *