【问题标题】:No response form website using MSXML2.XMLHTTP with POST and GET没有使用带有 POST 和 GET 的 MSXML2.XMLHTTP 的响应表单网站
【发布时间】:2021-06-24 06:12:21
【问题描述】:

我正在尝试使用 MSXML2.XMLHTTP 将数据从多个网站中的第二个传输到 Excel,而无需打开浏览器。意思是主页在数据输入后创建一个查询页面(或查询内容)。

我的代码:

Sub GetData()

Dim HTML As New HTMLDocument, HTMLDoc As New HTMLDocument
    Dim elmt As Object
    Dim L As Long
    Const URL = "http://www.zvg-portal.de/index.php?button=Termine%20suchen"
    Const URL1 = "http://www.zvg-portal.de/index.php?button=Suchen"
         
    With CreateObject("MSXML2.XMLHTTP")
    .Open "POST", URL, False
    .send "land_abk=be&button=suchen"
    .Open "GET", URL1, False
    .send
    HTML.body.innerHTML = .responseText
    End With
               
    Set elmt = HTML.querySelectorAll("TR")
    For L = 0 To elmt.Length - 1
    ActiveSheet.Cells(L + 2, 2) = elmt.Item(L).innerText
    Next

End Sub

什么都没有发生。我认为这是因为无法访问查询内容或未构建查询内容。可能是因为错误的BUTTON 代码?我还尝试了 button=submitsubmit=truesuchen=true,但没有成功。如何解决这个问题?谢了!

数据输入主站点的HTML:

<button type=submit>Suchen</button><button type=reset onClick="reset_form()">Zurücksetzen</button><br></h3></nobr><p>

<input type=hidden name=ger_name id=name=ger_name>

<!-- -->
<table border=0><tr><td ><b>Sortiert nach:&nbsp;</></td><td>
                <SELECT size=1 name=order_by><option value=2>Termin</option>
<option value=1>Aktualisierung</option>
<option value=3>Aktenzeichen</option>

</td> </tr>
</table>

<!--Land-->
<br>
<table border=0>
<tr><td><font color=red>*</font>&nbsp;<b>Land:</b></td></tr>
<tr><td>
<select size=1 name=land_abk onChange="updateAmtsgericht(this.value);" style="width:643px">
<option value=0>-- Bitte Bundesland ausw&auml;hlen --</option><option value='bw' >Baden-Wuerttemberg</option>
<option value='by' >Bayern</option>
<option value='be' >Berlin</option>

【问题讨论】:

    标签: excel vba web-scraping get xmlhttprequest


    【解决方案1】:

    您错过了在获取内容方面发挥重要作用的标题。试试这种方法:

    Sub GetData()
        Const URL = "http://www.zvg-portal.de/index.php?button=Suchen"
        Dim HTML As New HTMLDocument
        Dim elmt As Object, L As Long
    
        With CreateObject("MSXML2.XMLHTTP")
            .Open "POST", URL, False
            .setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
            .send ("land_abk=be")
            HTML.body.innerHTML = .responseText
        End With
                   
        Set elmt = HTML.querySelectorAll("tr > td")
        For L = 0 To elmt.Length - 1
            Debug.Print elmt.Item(L).innerText
        Next L
    End Sub
    

    【讨论】:

    • 感谢您的评论,我在代码中添加了标题,同样的问题:没有任何反应,并且 (body).innertext = same "ERROR wrong parameters!"
    • 你试过我贴在这里的那个吗?
    • OH NO >>> Debug.Print ActiveSheet.Cells。可以了,非常感谢楼主!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-03
    • 2013-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-23
    相关资源
    最近更新 更多