'How to get the locally formatted price out of these web pages
Microsoft has web pages showing the local prices for Windows in over 200 countries. For each country, there are separate web pages for Windows Pro, Windows Home, and Windows Workstation.
I'm trying to get the locally-formatted prices including currency symbol for each of the web pages. For many of them this works:
Const WEB_PRICE_HTML_CLASS_NAME_TYPE_1 As String = "pi-price-text"
Function GETWEBPRICE(url_web_price As String) As String
Dim oXMLHTTP As Object
Dim oHtmlDoc As Object
Dim collTopics As Object
Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP")
Set oHtmlDoc = CreateObject("htmlfile")
oXMLHTTP.Open "GET", url_web_price, False: DoEvents
oXMLHTTP.send: DoEvents
oHtmlDoc.body.innerHTML = oXMLHTTP.responseText: DoEvents
Set collTopics = oHtmlDoc.getElementsByClassName(WEB_PRICE_HTML_CLASS_NAME_TYPE_1): DoEvents
GETWEBPRICE = collTopics(0).textContent
End Function
An example web page for which that works is this one:
https://www.microsoft.com/uk-ua/d/windows-10-pro/df77x4d43rkt
But some of them have a different html structure, and that doesn't work, such as this one:
https://www.microsoft.com/en-au/d/windows-10-pro/df77x4d43rkt
How do I get the locally-formatted prices from the web pages with that html structure?
Solution 1:[1]
This uses a more general class, but does work for the AU site:
Const WEB_PRICE_HTML_CLASS_NAME_TYPE_1 As String = "font-weight-semibold"
Function GETWEBPRICE(url_web_price As String) As String
Dim oXMLHTTP As Object
Dim oHtmlDoc As Object
Dim collTopics As Object
Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP")
Set oHtmlDoc = CreateObject("htmlfile")
oXMLHTTP.Open "GET", url_web_price, False: DoEvents
oXMLHTTP.send: DoEvents
oHtmlDoc.body.innerHTML = oXMLHTTP.responseText: DoEvents
Set collTopics = oHtmlDoc.getElementsByClassName(WEB_PRICE_HTML_CLASS_NAME_TYPE_1): DoEvents
GETWEBPRICE = collTopics(0).innerText
End Function
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Spectral Instance |