jamescooper

Well-known Member
Joined
Sep 8, 2014
Messages
834
Hello struggling with this URL:

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.
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
It's not clear to me what you want. The items under "Customers who bought Ripen at Home Bananas also bought?"
 
Upvote 0
You need to work through the xhr requests using the developer tools in your browser and search for the information you're looking for
 
Upvote 0

Forum statistics

Threads
1,214,929
Messages
6,122,314
Members
449,081
Latest member
tanurai

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top