我从基于内部 Web 的 Dataservice (cognos) 获取数据时遇到问题。基本上,我将一个 GET 请求放在一起,例如"blah.com/cognosapi.dll?product=xxx&date=yyy...",将其发送到服务器并接收我可以存储为 HTML 并稍后解析为我的 excel 表单的网页。
我构建了一个过去运行良好的 VBA 程序,但是 web 服务发生了变化,现在他们正在显示“您的报告正在运行”页面,持续时间从 1 秒到 30 秒。所以当我调用我的函数时,我总是下载这个“你的报告正在运行”页面而不是数据。如何捕捉“报告正在运行”页面后自动加载的页面?
这是以 GETstring 和目标路径为参数的 DownloadFile 函数。
Public Function DownloadFile(sSourceUrl As String, _
sLocalFile As String) As Boolean
Dim HttpReq As Object
Set HttpReq = CreateObject("MSXML2.XMLHTTP")
Dim HtmlDoc As New MSHTML.HTMLDocument
HttpReq.Open "GET", sSourceUrl, False
HttpReq.send
If HttpReq.Status = 200 Then
HttpReq.getAllResponseHeaders
HtmlDoc.body.innerHTML = HttpReq.responseText
Debug.Print HtmlDoc.body.innerHTML
End If
'Download the file. BINDF_GETNEWESTVERSION forces
'the API to download from the specified source.
'Passing 0& as dwReserved causes the locally-cached
'copy to be downloaded, if available. If the API
'returns ERROR_SUCCESS (0), DownloadFile returns True.
DownloadFile = URLDownloadToFile(0&, _
sSourceUrl, _
sLocalFile, _
BINDF_GETNEWESTVERSION, _
0&) = ERROR_SUCCESS
End Function
谢谢大卫