http响应文本获取不完整的html [英] http response text fetching incomplete html

查看:706
本文介绍了http响应文本获取不完整的html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在excel vba中有一个代码(在下面给出),该代码可获取网页源html.该代码工作正常,但获取的html不完整.当执行行webpageSource = oHttp.ResponseText时,变量webpageSource包含"DOCTYPE html PUBLIC .......等等,直到/html结尾",这就是应该的样子.到这里一切都正确.但是下一行debug.print webpageSource仅显示(adsbygoogle = window.adsbygoogle || []).push({}); ......等等,直到/html"结尾的html的一半,为什么这样?我想从返回的响应文本中找到一些字符串,但是由于它不完整,所以无法这样做.有人可以阐明一下吗?

I have a code (given below) in excel vba that fetches web page source html. The code is working fine but the html that it fetches is incomplete. When the line webpageSource = oHttp.ResponseText is executed, the variable webpageSource contains "DOCTYPE html PUBLIC ....... etc etc till the end /html" and that is how it should be. Everything is correct till here. But the next line debug.print webpageSource prints only half the html from "(adsbygoogle = window.adsbygoogle || []).push({}); ...... etc etc till the end /html" Why is that so? I want to find some strings from the returned response text but since it is incomplete, I am unable to do so. Can someone shed some light on it?

谢谢

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,没有帮助:(

I also tried .WaitForResponse with no help :(

推荐答案

Debug.Print和/或直接窗口具有局限性.但是没有记录在案.

Debug.Print and/or the immediate window have limitations. Nowhere documented however they have.

因此,请尝试将webpageSource写入文件:

So try writing the webpageSource to a file:

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

文件是否包含所有内容?

Does the file contain all content?

这篇关于http响应文本获取不完整的html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆