jamescooper
Well-known Member
- Joined
- Sep 8, 2014
- Messages
- 840
So for this website: https://www.tesco.com/groceries/en-GB/products/268279288
The following code pulls the Price/price per unit etc.
Now trying to adapt to pull the price (78p) on this website and cannot seem to adapt it to suit when inspecting the element. Any ideas? Any literature on this would be great too thanks.
https://www.sainsburys.co.uk/shop/gb/groceries/bananas-grapes/sainsburys-loose-fairtrade-bananas
The following code pulls the Price/price per unit etc.
Code:
Private Function getprices(ByVal URL As String) As Variant
Dim source As Object
Dim http As New XMLHTTP60, html As New HTMLDocument
Dim ret(1 To 5) As String
Dim elem As Object
With http
.Open "GET", URL, False
.send
html.body.innerHTML = .responseText
End With
Set elem = html.querySelector(".price-details--wrapper .value")
If Not elem Is Nothing Then
ret(1) = elem.innerText
Else
ret(1) = "N/A"
End If
Set elem = html.querySelector(".price-per-quantity-weight .value")
If Not elem Is Nothing Then
ret(2) = elem.innerText
Else
ret(2) = "N/A"
End If
Set elem = html.querySelector(".price-per-quantity-weight .weight")
If Not elem Is Nothing Then
ret(3) = elem.innerText
Else
ret(3) = "N/A"
End If
Set elem = html.querySelector(".promotions-wrapper.hidden-small.hidden-medium-small-only .offer-text")
If Not elem Is Nothing Then
ret(4) = elem.innerText
Else
ret(4) = "No"
End If
Set elem = html.querySelector(".promotions-wrapper.hidden-small.hidden-medium-small-only .dates")
If Not elem Is Nothing Then
ret(5) = elem.innerText
Else
ret(5) = "None"
End If
getprices = ret
End Function
Now trying to adapt to pull the price (78p) on this website and cannot seem to adapt it to suit when inspecting the element. Any ideas? Any literature on this would be great too thanks.
https://www.sainsburys.co.uk/shop/gb/groceries/bananas-grapes/sainsburys-loose-fairtrade-bananas
Code:
Private Function getprices(ByVal URL As String) As Variant
Dim source As Object
Dim http As New XMLHTTP60, html As New HTMLDocument
Dim ret(1 To 1) As String
With http
.Open "GET", URL, False
.send
html.body.innerHTML = .responseText
End With
ret(1) = html.querySelector(".pricing .priceperunit").innerText
End Function