jamescooper
Well-known Member
- Joined
- Sep 8, 2014
- Messages
- 840
Hello struggling with this URL:
Trying to obtain the list of items:
ASDA Grower's Selection Ripen at Home Bananas
etc...
Option Explicit
Any ideas please?
Thanks.
HTML:
https://groceries.asda.com/aisle/fresh-food-bakery/fruit/bananas/112447
Trying to obtain the list of items:
ASDA Grower's Selection Ripen at Home Bananas
etc...
Option Explicit
Code:
Sub Asdas_Pull_Products_and_Prices()
Dim XMLPage As New MSXML2.XMLHTTP60
Dim HTMLDoc As New MSHTML.HTMLDocument
Dim LastRow As Long
Dim htmlH3s As MSHTML.IHTMLElementCollection
Dim htmlH3 As MSHTML.IHTMLElement
Dim htmlDivs As MSHTML.IHTMLElementCollection
Dim htmlDiv As MSHTML.IHTMLElement
Dim anchors As IHTMLElementCollection
Dim anchor As HTMLAnchorElement
Dim arrItems_1, arrItems_2, arrItems_3, arrItems_4 As Variant
Dim strProduct, strPrice, strUnitPrice, StrURL As String
Dim rngURL As Range
'Create URL and sent request
For Each rngURL In Worksheets("Sheet1").Range("S2", Worksheets("Sheet1").Range("S" & Rows.Count).End(xlUp))
XMLPage.Open "GET", rngURL, False
XMLPage.send
DoEvents
'Get the source (code) of the webpage
HTMLDoc.body.innerHTML = XMLPage.responseText
LastRow = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row + 1
'Set reference to all h3-elements in htmlDoc.body.innerHTML
Set htmlH3s = HTMLDoc.getElementsByTagName("div")
'Loop through all h3-elements to get the product name
For Each htmlH3 In htmlH3s
If htmlH3.className = "co-item__title-container" Then
strProduct = strProduct & "|" & htmlH3.innerText
End If
Next
Next
'Store all results in an Array
arrItems_1 = Split(Mid(strProduct, 2), "|")
'Insert the results directly into Sheet1
Sheets("Sheet1").Cells(LastRow, 1).Resize(UBound(arrItems_1) + 1) = Application.Transpose(arrItems_1)
End Sub
Any ideas please?
Thanks.