MITHU
MITHU

Reputation: 154

"Get" request method not working in vba

I've written a code to fetch the name of a restaurant using its phone number applying "GET" http method but what i'm doing wrong with this process is beyond my knowledge. So, if anybody extends a helping hand to resolve this issue, i would be very grateful to him. Thanks in advance.

Sub test()

Dim xmlhttp As New MSXML2.XMLHTTP60, myHtml As New HTMLDocument
Dim PostData As String, ele As Object, thing As Object
Dim x As Long

x = 2

PostData = "what=5197365924"
xmlhttp.Open "GET", "http://mobile.canada411.ca/search/" & PostData, False
xmlhttp.setRequestHeader "Content-Type", "text/xml"
xmlhttp.send
myHtml.body.innerHTML = xmlhttp.responseText


Set ele = myHtml.getElementsByClassName("merchant-title__name jsShowCTA")

For Each thing In ele
    Cells(x, 1) = thing.innertext
    x = x + 1
Next thing

End Sub

Upvotes: 0

Views: 250

Answers (2)

MITHU
MITHU

Reputation: 154

Lots of issues were there in my post. However, I've fixed it already. Now, it is good to go.

Sub reverse_search()
    Dim http As New XMLHTTP60, html As New HTMLDocument
    Dim ArgumentString As String, post As Object

    ArgumentString = "what=5197365924&where=Canada&redirect=reversetobusiness"

    With http
        .Open "GET", "https://www.yellowpages.ca/bus/Ontario/Amherstburg/Downtown-Expresso-Cafe/522901.html?" & ArgumentString, False
        .setRequestHeader "Content-Type", "text/xml"
        .setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36"
        .send
        html.body.innerHTML = .responseText
    End With

    For Each post In html.getElementsByClassName("merchant-title__name")
        x = x + 1: Cells(x, 1) = post.innerText
    Next post
End Sub

Upvotes: 0

Mario Apra
Mario Apra

Reputation: 93

Your code is pretty fine, but your endpoint does not show anything, you can test in your browser and you will see.

I suggest you read the YellowAPI doc and test this kind of endpoint, changing the values YOUR_API_KEY_HERE and YOUR_UID_HERE.

Upvotes: 2

Related Questions