I am using the code below code but it brings the value of 'src' instead of 'href' for some reason. Anyone can help please?
Sub bringfox(txt As String)
Dim oHtml As HTMLDocument
Dim oElement As Object
Set oHtml = New HTMLDocument
maintext2 = "https://www.jjfox.co.uk/cigars/show/all.html"
With CreateObject("WINHTTP.WinHTTPRequest.5.1")
.Open "GET", maintext2 & gr, False
.send
oHtml.body.innerHTML = .responseText
End With
counter = cnt
'oElement(i).Children(0).getAttribute ("href")
Set oElement = oHtml.getElementsByClassName("products-grid products-grid--max-3-col")(0).getElementsByTagName("a")
i = 0
While i < oElement.Length
Debug.Print oElement(i).Children(0).getAttribute("href")
i = i + 1
Wend
End Sub
You could try using a CSS selector.
This is a reduced version of the full selector that targets
a
tags within the products category. You then parse theouterHTML
for the hrefs as that is where the information is located.Site image (Sample view)
Output from code (Sample view)
Code
Or more simply, use the following