'Importing live data

My code can not import the live price because I only know how to use class and it's like elements a split into id as well in some browsers. The page I choose rather has the use of div with I pasted. My code is

Sub Get_Web_Data_ETH()

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

' Code 01

' Website to go to. website = "https://www.luno.com/trade/markets/ETHZAR"

' 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 price from the specified element on the page. price = html.getElementsByClassName(" ZAR 45,446 ").Item(0).getElementsByTagName("<\div>")

' Code 02

' Website to go to. website = "https://www.luno.com/trade/markets/ETHZAR"

' 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 exchangerate from the specified element on the page. exchangerate = html.getElementsByClassName("24h Changeforward0.71%").Item(0).innerText

' Output the price into a message box. 'ActiveSheet.Range("B3").Value = price 'ActiveSheet.Range("C2").Value = exchangerate

MsgBox price MsgBox exchangerate

End Sub



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source