gpt4 book ai didi

vba - http响应文本获取不完整的html

转载 作者:行者123 更新时间:2023-12-02 03:03:38 25 4
gpt4 key购买 nike

我在 excel vba 中有一段代码(如下所示),可以获取网页源 html。该代码工作正常,但它获取的 html 不完整。当执行 webpageSource = oHttp.ResponseText 行时,变量webpageSource包含“DOCTYPE html PUBLIC .......等直到最后/html”,这就是它应该的样子。到这里为止一切都是正确的。但下一行 debug.printpageSource 仅打印“(adsbygoogle = window.adsbygoogle || []).push({}); ......等的一半html,直到end/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 没有帮助:(

最佳答案

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

文件是否包含所有内容?

关于vba - http响应文本获取不完整的html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33042430/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com