Sub ScrapeDataFromWebsite()
Dim HttpReq As Object
Dim HTMLDoc As Object
Dim URL As String
Dim Element As Object
Dim Data As String
URL = "https://www.example.com"
Set HttpReq = CreateObject("MSXML2.XMLHTTP")
HttpReq.Open "GET", URL, False
HttpReq.send
Set HTMLDoc = CreateObject("htmlfile")
HTMLDoc.body.innerHTML = HttpReq.responseText
Set Element = HTMLDoc.getElementById("elementID")
Data = Element.innerText
Debug.Print Data 'Replace with your desired output action
End Sub
This code uses the MSXML2.XMLHTTP object to make an HTTP request to a website and the htmlfile object to parse the response as HTML. You can customize the URL and element ID to scrape data from any website.
