我一直在努力寻找答案,但似乎找不到任何有用的东西。
基本上,我是从一个网站上拉取的,当您在该页面上时,该网站会加载更多项目。我希望我的代码在加载完成后提取最终数据,但不知道如何让 XML httprequest 等待。
Edited:
Sub pullsomesite()
Dim httpRequest As XMLHTTP
Dim DataObj As New MSForms.DataObject
Set httpRequest = New XMLHTTP
Dim URL As String
URL = "somesite"
With httpRequest
.Open "GET", URL, True
.setRequestHeader "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT"
.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
Application.Wait Now + TimeValue("0:02:00")
.send
' ... after the .send call finishes, you can check the server's response:
End With
While Not httpRequest.readyState = 4 '<---------- wait
Wend
If httpRequest.Status = 200 Then
Application.Wait Now + TimeValue("0:00:30")
Debug.Print httpRequest.responseText
'continue...
End If
'Debug.Print httpRequest.Status
'Debug.Print httpRequest.readyState
'Debug.Print httpRequest.statusText
DataObj.SetText httpRequest.responseText
DataObj.PutInClipboard
With Sheets("Sheet1")
.Activate
.Range("A1000000").End(xlUp).Offset(1, 0).Select
.PasteSpecial Format:="Text", Link:=False, DisplayAsIcon:=False, NoHTMLFormatting:=True
End With
End Sub
截屏
尝试等待就绪状态和响应正文不包含“更新”一词:
Option Explicit
Sub pullSomeSite()
Dim httpRequest As XMLHTTP
Set httpRequest = New XMLHTTP
Dim URL As String
URL = "SomeSite"
With httpRequest
.Open "GET", URL, False
.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
.send
End With
With httpRequest
While Not .ReadyState = 4 '<---------- wait
Application.Wait Now + TimeValue("0:00:01")
Wend
If .Status = 200 Then
While InStr(1, .responseText, "Updating", 0) > 0 '<---------- wait again
Application.Wait Now + TimeValue("0:00:01")
Wend
Debug.Print .responseText
'continue...
End If
End With
End Sub
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)