Pass Parameters in VBA HTTP Post Request

前端 未结 2 1495
予麋鹿
予麋鹿 2021-01-18 18:05

I\'m trying to do a simple post request on the main search bar of http://forums.egullet.org/. (This is one example, but I\'m trying to build a tool that will work with many

相关标签:
2条回答
  • 2021-01-18 18:33

    I think you need an ampersand where you have a question mark

    argumentString = "&search_term=eggs&search_app=forums"
    
    0 讨论(0)
  • To make it more concise and get the title of that target page:

    Sub httpPost()
        Dim http As New XMLHTTP60, html As New HTMLDocument
        Dim post As Object, argstr As String
    
        argstr = "type=all&q=eggs"
    
        With http
            .Open "POST", "https://forums.egullet.org/search/?", False
            .setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36"
            .setRequestHeader "Content-type", "application/x-www-form-urlencoded"
            .send argstr
            html.body.innerHTML = .responseText
        End With
    
        For Each post In html.getElementsByClassName("ipsStreamItem_title")
            With post.getElementsByTagName("a")
                If .Length Then Row = Row + 1: Cells(Row, 1) = .Item(0).innerText
            End With
        Next post
    End Sub
    
    0 讨论(0)
提交回复
热议问题