2

我在 excel vba 中有一个获取网页源 html 的代码(如下所示)。代码工作正常,但它获取的 html 不完整。执行该行时webpageSource = oHttp.ResponseText,变量webpageSource包含“DOCTYPE html PUBLIC ....... etc etc直到结束/html”,这就是它应该的样子。到这里为止一切都是正确的。但是下一行debug.print webpageSource只打印了“(adsbygoogle = window.adsbygoogle || []).push({}); ...... etc 等到​​最后 /html” 中的一半 html” 为什么会这样?我想从返回的响应文本中找到一些字符串,但由于它不完整,我无法这样做。有人可以解释一下吗?

谢谢

Sub source()
    Dim oHttp As New WinHttp.WinHttpRequest
    Dim sURL As String
    Dim webpageSource As String
    sURL = "http://www.somewebsite.com"
    oHttp.Open "GET", sURL, False
    oHttp.send
    webpageSource = oHttp.ResponseText
    debug.print webpageSource
End Sub

编辑:我也试过 .WaitForResponse 没有帮助:(

4

1 回答 1

4

Debug.Print和/或即时窗口有限制。但是他们没有记录。

所以尝试将其写入webpageSource文件:

Sub source()
    Dim oHttp As New WinHttp.WinHttpRequest
    Dim sURL As String
    Dim webpageSource As String
    sURL = "http://www.google.com"
    oHttp.Open "GET", sURL, False
    oHttp.send
    webpageSource = oHttp.ResponseText

    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set oFile = FSO.CreateTextFile("webpageSource.txt")
    oFile.Write webpageSource
    oFile.Close

    Shell "cmd /C start webpageSource.txt"

End Sub

文件是否包含所有内容?

于 2015-10-09T16:41:48.847 回答