This code works perfectly in Excel. It just finds the current price of a coin. However in Access this line
Set container1 = html.querySelector("#productPrice-product-template span:last-child")
gives error -2147024809 Invalid argument.
Function fncScrapeGOLDvalue() As Integer
Dim html As HTMLDocument
Set html = New HTMLDocument
Dim returnValue As Integer
With CreateObject("MSXML2.XMLHTTP")
.Open "GET", "https://www.allgoldcoins.co.uk/products/2013-queen-elizabeth-ii-60th-anniversary-of-the-coronation-5-gold-proof-coin?variant=41603767205941", False
.send
html.body.innerHTML = .responseText
End With
Dim container1 As Object
Set container1 = html.querySelector("#productPrice-product-template span:last-child")
fncScrapeGOLDvalue = CInt(container1.innerText)
End Function
if I modify that line to
Set container1 = html.querySelector("#productPrice-product-template ")
It works!! but it's not exactly what I want
Try this:
Update:
I checked the above code as following and it works:
But there is something to be considered: There are actually 2 spans; first has a
aria-hidden=truewhich theQuerySelectorAllcannot detect (don't know why). The second span has aclass="visually-hidden"and this is the one in collection.I suggest be more specific with CSS selector; Use this to select the second span: