无法在 ServerXMLHTTP 请求中设置自定义超时
Unable to set customized timeout within ServerXMLHTTP request
我在 vba 中编写了一个脚本,用于在发出代理请求后从网站上抓取第一个 post。我在我的 vba 脚本中发出 http 请求时使用了代理(不在代理列表中)以检查 post 的总长度。成功发送请求后,脚本应解析第一个 post 和正在使用的代理并退出循环。
Sometimes the script work in the right way but most of the times the script takes ages to complete the operation even when I've defined timeout
before sending request. At this point I'm highly dubious as to whether I could fill in the timeout
parameter in the right way. What I expect is that the script will wait upto that time for any response, othrwise it will throw timeout
error and go for the next request.
到目前为止我写了:
Sub HandleTimeOut()
Dim Http As New ServerXMLHTTP60, Html As New HTMLDocument
Dim elem As Object, proxyList As Variant, oProxy As Variant
proxyList = [{"50.246.120.125:8080","198.204.253.115:3128","98.172.142.99:8080","207.188.231.141:8080"}]
For Each oProxy In proxyList
With Http
.Open "GET", "https://whosebug.com/questions/tagged/web-scraping", True
.setRequestHeader "User-Agent", "Mozilla/5.0"
.setProxy 2, oProxy
.setTimeouts 600000, 600000, 15000, 15000
On Error Resume Next
.send
While .readyState < 4: DoEvents: Wend
Html.body.innerHTML = .responseText
Set elem = Html.querySelectorAll(".summary .question-hyperlink")
On Error GoTo 0
End With
If elem.Length > 0 Then
[A1] = oProxy
[B1] = elem(0).innerText
Exit For
End If
Next oProxy
End Sub
设置timeout
五秒的正确方法是什么?
.Open "GET", "https://whosebug.com/questions/tagged/web-scraping", True
应该是
.Open "GET", "https://whosebug.com/questions/tagged/web-scraping", False
我在 vba 中编写了一个脚本,用于在发出代理请求后从网站上抓取第一个 post。我在我的 vba 脚本中发出 http 请求时使用了代理(不在代理列表中)以检查 post 的总长度。成功发送请求后,脚本应解析第一个 post 和正在使用的代理并退出循环。
Sometimes the script work in the right way but most of the times the script takes ages to complete the operation even when I've defined
timeout
before sending request. At this point I'm highly dubious as to whether I could fill in thetimeout
parameter in the right way. What I expect is that the script will wait upto that time for any response, othrwise it will throwtimeout
error and go for the next request.
到目前为止我写了:
Sub HandleTimeOut()
Dim Http As New ServerXMLHTTP60, Html As New HTMLDocument
Dim elem As Object, proxyList As Variant, oProxy As Variant
proxyList = [{"50.246.120.125:8080","198.204.253.115:3128","98.172.142.99:8080","207.188.231.141:8080"}]
For Each oProxy In proxyList
With Http
.Open "GET", "https://whosebug.com/questions/tagged/web-scraping", True
.setRequestHeader "User-Agent", "Mozilla/5.0"
.setProxy 2, oProxy
.setTimeouts 600000, 600000, 15000, 15000
On Error Resume Next
.send
While .readyState < 4: DoEvents: Wend
Html.body.innerHTML = .responseText
Set elem = Html.querySelectorAll(".summary .question-hyperlink")
On Error GoTo 0
End With
If elem.Length > 0 Then
[A1] = oProxy
[B1] = elem(0).innerText
Exit For
End If
Next oProxy
End Sub
设置timeout
五秒的正确方法是什么?
.Open "GET", "https://whosebug.com/questions/tagged/web-scraping", True
应该是
.Open "GET", "https://whosebug.com/questions/tagged/web-scraping", False