vbaexcelresponsetextwinhttprequest

http response text fetching incomplete 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?

Thanks

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

EDIT: I also tried .WaitForResponse with no help :(


Solution

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

    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?