(Solved) – Use VBA to crawl span label in webpage

  • by
(solved)-–-use-vba-to-crawl-span-label-in-webpage

I am having trouble using VBA to get data from a website… This method generate bugs coz the html object does not support getelementbyclassname. May I know is there any alternative way to get the data I want?

webpage discription

Option Explicit

Public Sub getlist()
[a:b].ClearContents 'clear all contents

   Dim strurl As String
   strurl = "https://www.bloomberg.com/quote/HSB22A2:LX"
   Dim html As Object: Set html = CreateObject("htmlfile")
   With CreateObject("msxml2.xmlhttp")
       .Open "get", strurl, False
       .send
       Do While .readyState <> 4
           DoEvents
       Loop
       'html.body.innerHtml = .responseText
   End With

   With html.getElementsByClassName("fieldLabel__9f45bef7")(0) '-->generate bugs
        'MsgBox (.innerText)

   End With

End Sub

Leave a Reply

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