• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Post request brings unexpected results

shahin

Active Member
Writing a macro in post request when i run it, it brings unexpected response which i don't want. Perhaps, it is unable to fetch response from the targeted page. Can't identify the mistake I'm doing? The original url I'm pasting under my code.

Box to be checked before performing search:

Industry Role = Professional Services Providers
Other Criterion = APEX

Code:
Sub Xmlpost()
Dim http As New MSXML2.XMLHTTP60
Dim html As New HTMLDocument
Dim postdata As String

postdata = "DoMemberSearch=1&mas_last=&mas_comp=&mas_city=&mas_stat=&mas_cntr=&mas_type=Professional+Services+Providers&OtherCriteria=1"
With http
    .Open "POST", "https://www.infocomm.org/cps/rde/xchg/infocomm/hs.xsl/memberdirectory.htm", False
    .setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    .setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
    .send postdata
    html.body.innerHTML = .responseText
End With
MsgBox http.responseText
End Sub


Original url = "https://www.infocomm.org/cps/rde/xchg/infocomm/hs.xsl/memberdirectory.htm"

How I Searched is shown in the picture:
 

Attachments

  • Untitled.jpg
    Untitled.jpg
    17.7 KB · Views: 5
To be more specific, If what i have written in my code is right then i suppose i should have been able to scrape names from that page with this bit of code:

Code:
Sub Xmlpost()
Dim http As New MSXML2.XMLHTTP60
Dim html As New HTMLDocument
Dim Items As Object, Item As Object, Elem As Object
Dim postdata As String

postdata = "DoMemberSearch=1&mas_last=&mas_comp=&mas_city=&mas_stat=&mas_cntr=&mas_type=Professional+Services+Providers&OtherCriteria=1"
With http
    .Open "POST", "https://www.infocomm.org/cps/rde/xchg/infocomm/hs.xsl/memberdirectory.htm", False
    .setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    .setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
    .send postdata
    html.body.innerHTML = .responseText
End With
'MsgBox http.responseText

Set Items = html.getElementsByClassName("paginationDisplayItem")

For Each Item In Items
Set Elem = Item.getElementsByTagName("a")(0)
    x = x + 1
    Cells(x, 1) = Elem.innerText
Next Item
End Sub
 
Found the solution. The class element contains noting as it shows when inspected. The trick is in the ID. Thanks to sir CHIHIRO for providing me with a guidance once why should i care about viewing source code.
Code:
Sub Xmlpost()
Dim http As New MSXML2.XMLHTTP60
Dim html As New HTMLDocument
Dim Items As Object, Item As Object, Elem As Object
Dim postdata As String

postdata = "DoMemberSearch=1&mas_last=&mas_comp=&mas_city=&mas_stat=&mas_cntr=&mas_type=Professional+Services+Providers&OtherCriteria=1"
With http
    .Open "POST", "https://www.infocomm.org/cps/rde/xchg/infocomm/hs.xsl/memberdirectory.htm", False
    .setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    .setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
    .send postdata
    html.body.innerHTML = .responseText
End With

Set Items = html.getElementById("paginationDataPool").getElementsByTagName("a")
For Each Item In Items
    x = x + 1
    Cells(x, 1) = Item.innerText
Next Item
End Sub
 
Back
Top