Parsing HTML

jamescooper

Well-known Member
Joined
Sep 8, 2014
Messages
840
Hello,

Trying to pull all the names of the items and then the price on this page,

https://www.tesco.com/groceries/en-GB/shop/fresh-food/all?include-children=true&page=1
e.g.
[h=3]Tesco British Salted Block Butter 250G £1.50
Tesco Gala Apple Minimum 5 Pack £1.60

But the code fails on this line:
Code:
[FONT=Verdana]Sheets(1).Cells(i, 1).Value = titleElem.getElementsByTagName("a")(0).innerText[/FONT]

[/h]
Code:
Public Sub Data_Pull()


Dim http As Object, html As New HTMLDocument, topics As Object, titleElem As Object, detailsElem As Object, topic As HTMLHtmlElement
Dim i As Integer
Set http = CreateObject("MSXML2.XMLHTTP")


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("content-wrapper")


i = 2


For Each topic In topics
Set titleElem = topic.getElementsByTagName("td")(2)
Sheets(1).Cells(i, 1).Value = titleElem.getElementsByTagName("a")(0).innerText
i = i + 1


Next


End Sub

Any ideas,

Thanks.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Managed to resolve, it is:

Code:
Public Sub Data_Pull()


Dim http As Object, html As New HTMLDocument, topics As Object, titleElem As Object, detailsElem As Object, topic As HTMLHtmlElement
Dim i As Integer
Set http = CreateObject("MSXML2.XMLHTTP")


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")


i = 2


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


End Sub
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,183
Members
452,615
Latest member
bogeys2birdies

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