shahin
Active Member
Another alternative to avoid "On error resume next":
Code:
Sub GetData()
Const URL = "https://www.yellowpages.com.au/search/listings?clue=coffee+shops&locationClue=all+states&lat=&lon=&selectedViewMode=list"
Dim http As New XMLHTTP60, html As New HTMLDocument
Dim elem As Object, post As Object, stor As Object, top As Object, obj As HTMLHtmlElement
With http
.Open "GET", URL, False
.send
html.body.innerHTML = .responseText
End With
Set elem = html.getElementsByClassName("listing listing-search listing-data")
For Each obj In elem
x = x + 1
Set post = obj.getElementsByClassName("listing-name")
Set stor = obj.getElementsByClassName("click-to-call contact contact-preferred contact-phone")
Set top = obj.getElementsByClassName("listing-address mappable-address mappable-address-with-poi")
If post.Length Then Cells(x + 1, 1) = post(0).innerText
If stor.Length Then Cells(x + 1, 2) = stor(0).innerText
If top.Length Then Cells(x + 1, 3) = top(0).innerText
Next obj
End Sub