首页 > 解决方案 > 在 VBA XMLHTTP 代码中需要帮助以获取完整的页面加载或任何等待机制

问题描述

您好写了下面的代码来使用 VBA 的 XMLHTTP 方法获取整个页面加载,但每次我得到部分加载的数据。

我只想在它完全加载后完成获取页面详细信息,我只希望通过 xmlhttp 而不是通过 Internet Explorer 类。所以我尝试了所有等待机制,但它不起作用。.

Option Explicit
Sub showXML()
    Dim xmlpage As New MSXML2.XMLHTTP60
    Dim HTMLDoc As New MSHTML.HTMLDocument
    Dim url As String

    url = "http://www.the-stockmarket.com/product/Moen-MO100429-Repair-Kit-35549?Ns=Primary_Finish%7C1%7C%7CSort_Order%7C1&No=26796&N=3000556+3000571+3000557+3000558+3000559+3000560+3000561+3000562+3000563+3000564+3000565+3000566"

    xmlpage.Open "GET", url, False
    Application.Wait (Now + TimeValue("0:00:20"))
    xmlpage.send

    With xmlpage

        While Not .readyState = 4                '<---------- wait
            Application.Wait Now + TimeValue("0:00:01")
        Wend

        If .Status = 200 Then
            While InStr(1, .responseText, "Retrieving ...", 0) > 0 '<---------- wait again
                Application.Wait Now + TimeValue("0:00:01")
            Wend
        End If
    End With

    Dim myfile As String
    myfile = "D:\test1.txt"

    Open myfile For Output As #11

    Write #11, xmlpage.responseText

    Close #11
End Sub

我需要完整加载的页面数据。目前我正在获取带有文本“正在检索......”的数据,但在完成加载的数据中,我会在那里收到一些数字。

标签: excelvbaxmlhttprequest

解决方案


推荐阅读