excel - 在 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
我需要完整加载的页面数据。目前我正在获取带有文本“正在检索......”的数据,但在完成加载的数据中,我会在那里收到一些数字。
解决方案
推荐阅读
- c - 如何使用 mpc 解析器定义标准数学符号
- laravel - Laravel GET 请求变量与 url 混淆
- php - 如何检查数据库 CodeIgniter 上是否存在行
- office-js - 使用 WordAPI 更改整个文档的字体
- java - 为什么只为 *const_n JVM 指令定义了这样的常量范围?
- amazon-web-services - AWS SQS 死信队列 - 仅在某些情况下
- sql - 如何在 BigQuery 上使用 SQL 计算两个数字之间的百分比?
- java - Spring Data JPA 是否需要 Spring Boot?
- sql - 插入表格后,小数点后的数字变为0
- arrays - arango Foxx 中的 AQL 模板无法与数组一起正常工作