jamescooper
Well-known Member
- Joined
- Sep 8, 2014
- Messages
- 840
Hello following code works fine for 1 URL, I am trying to adapt so it runs for all the numerical pages it can find from the baseURL, so for instance the 1 up to the max until there is an error, is this possible?
Thanks.
baseUrl = "https://www.tesco.com/groceries/en-GB/shop/fresh-food/all?include-children=true&page=1"
Thanks.
baseUrl = "https://www.tesco.com/groceries/en-GB/shop/fresh-food/all?include-children=true&page=1"
Code:
Public Sub Data_Pull_Products_and_Prices()
Dim http As Object, html As New HTMLDocument, topics As Object, topics2 As Object, titleElem As Object, topic As HTMLHtmlElement
Dim i As Integer
Dim j As Integer
Set http = CreateObject("MSXML2.XMLHTTP")
baseUrl = "https://www.tesco.com/groceries/en-GB/shop/fresh-food/all?include-children=true&page=1"
URL = URL = baseURL &
http.Open "GET", "https://www.tesco.com/groceries/en-GB/shop/fresh-food/all?include-children=true&page=1", False
http.send
html.body.innerHTML = http.responseText
Set topics = html.getElementsByClassName("product-details--wrapper")
Set topics2 = html.getElementsByClassName("price-control-wrapper")
i = 1
For Each topic In topics
Set titleElem = topic.getElementsByTagName("div")(0)
Sheets(1).Cells(i, 1).Value = titleElem.getElementsByTagName("a")(0).innerText
i = i + 1
Next
j = 1
For Each topic In topics2
Set titleElem = topic.getElementsByTagName("div")(0)
Sheets(1).Cells(j, 2).Value = titleElem.getElementsByTagName("span")(0).innerText
j = j + 1
Next
End Sub