Webscraping Grocery Website

JohnDoe1976

New Member
Joined
Nov 17, 2020
Messages
1
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2013
  5. 2011
  6. 2010
  7. 2007
Platform
  1. Windows
Hi There,
I'm having a lot of trouble trying to get a simple webscrape to work.
I am using a dynamic URL to search for a product (in this case 'GREENE KING ABBOT ALE') and what I'd like to do is have all the available links that return from the site to appear in column A of sheet called 'Single'

This code only intermittently works - it did work once, then it didnt again - i think there are Javascript elements blocking the script from returning ALL urls.
The URL i know is on the page is:

"https://groceries.aldi.co.uk/en-GB/p-greene-king-abbot-ale-500ml/5010549104614"

however I can't get this particular link to copy into my sheet again.

Please can you help - spent all day getting this far and I'm running out of ideas : (


VBA Code:
Sub webscrape()

Sheets("Single").Cells.Clear

Dim doc As HTMLDocument
Dim output As Object

Set IE = CreateObject("InternetExplorer.Application")

'Set IE = New InternetExplorer
IE.Visible = False
IE.Navigate "https://groceries.aldi.co.uk/en-GB/Search?keywords=GREENE+KING+ABBOT+ALE"

Do
    DoEvents
    Loop Until IE.ReadyState = READYSTATE_COMPLETE

Set doc = IE.Document
Set output = doc.getElementsByTagName("a")

i = 5
For Each Link In output
    Sheets("Single").Range("A" & i).Value = Link
    i = i + 1

Next

End Sub
 
Last edited by a moderator:

Some videos you may like

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

Watch MrExcel Video

Forum statistics

Threads
1,118,473
Messages
5,572,330
Members
412,457
Latest member
Shawann
Top