Get HTML document using XMLHTTP vs InternetExplorer

Vantom

Board Regular
Joined
Feb 28, 2014
Messages
65
When using the 'HTML_XMLHTT' sub I only get(replaced '<'/'>' with '#'):
#HEAD##/HEAD#
#BODY#
#CENTER#
#H1#404 Not Found#/H1##/CENTER#
#HR#

#CENTER#nginx/1.14.0#/CENTER#
#!-- a padding to disable MSIE and Chrome friendly error page --#
#!-- a padding to disable MSIE and Chrome friendly error page --#
#!-- a padding to disable MSIE and Chrome friendly error page --#
#!-- a padding to disable MSIE and Chrome friendly error page --#
#!-- a padding to disable MSIE and Chrome friendly error page --#
#!-- a padding to disable MSIE and Chrome friendly error page --#
#/BODY#
And with the 'HTML_IE' sub, I get the document. So how do I prevent the error using 'XMLHTTP'?
Code:
Option Explicit
Private Const URL As String = "https://www.oslobors.no/ob_eng/" _
                            & "markedsaktivitet/#/details/EQNR.OSE/overview"

Private Sub HTML_XMLHTTP()
    Dim oXMLHTTP  As Object
    Dim htmlObj  As Object
        Sheet1.Cells.Clear
        Set htmlObj = CreateObject("htmlfile")
        Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP")
    
        With oXMLHTTP
            .Open "GET", URL, False
            .send
            htmlObj.body.innerHTML = .responseText
        End With
        
        Call Get_DOM(htmlObj)
End Sub

Private Sub HTML_IE()
    Dim IE As Object
        Sheet1.Cells.Clear
        Set IE = CreateObject("InternetExplorer.Application")
        With IE
            .navigate URL
            Do Until .readyState = 4
                DoEvents
            Loop
            Call Get_DOM(IE.Document)
            .Quit
        End With
End Sub

Private Sub Get_DOM(HTMLDoc As Object)
    Dim arr() As String
    Dim vItem As Variant
    Dim i As Integer
    Dim objHtml As Object
    
        Set objHtml = HTMLDoc.getElementsByTagName("html")
        
        arr = Split(objHtml(0).innerHTML, vbLf)
        
        For Each vItem In arr
            i = i + 1
            Cells(i, 1).Value = vItem
        Next vItem
 End Sub
 
Last edited:

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Changing 'XMLHTTP' to 'ServerXMLHTTP' and going via 'tinyurl' does not give an error, but the html is different from IE.
Code:
Private Sub HTML_XMLHTTP()
    Dim oXMLHTTP  As Object
    Dim htmlObj  As Object
    Dim Tiny_URL As String
    Dim strURL As String
        Sheet1.Cells.Clear
        
        Set htmlObj = CreateObject("htmlfile")
        Set oXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP")
        Tiny_URL = "https://tinyurl.com/api-create.php?url="
        
        With oXMLHTTP
        
            .Open "GET", Tiny_URL & URL, False
            .send
            strURL = .responseText
            
            .Open "GET", strURL, False
            .send
            htmlObj.body.innerHTML = .responseText
            
        End With
        
        Call Get_DOM(htmlObj)
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,749
Messages
6,174,280
Members
452,554
Latest member
Louis1225

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top