Question Using GetElementById (without web browser)

Roots021

New member
Joined
Mar 19, 2017
Messages
1
Programming Experience
3-5
Hi all,

This is my first post in here.

I am trying to create a code to get HTML data from the web (without using a web browser element), creating a local variable to store the data and being able to parse it later on using the GetElementById method.

The problem is that I am getting an error and I?m not sure how to fix it.

the code is as follows:

VB.NET:
Imports mshtml

Sub Getelement()  

        Dim url As String
        Dim XMLHTTP As Object, html As IHTMLDocument2 = New HTMLDocument
        Dim obj_tbl As HTMLElementCollection

        url = "url to be used "

        XMLHTTP = CreateObject("MSXML2.XMLHTTP")
        XMLHTTP.Open("GET", url, False)
        XMLHTTP.setRequestHeader("cache-control", "no-cache, must revalidate")
        XMLHTTP.send()

        html.write(XMLHTTP.responseText

        obj_tbl = html.getelementbyid("id")

    End Sub

The error returned is : "Unable to cast COM object of type 'System.__ComObject' to interface type 'mshtml.HTMLElementCollection'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{3050F56B-98B5-11CF-BB82-00AA00BDCE0B}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))."


I have looked for a solution everywhere, but no way to find something without using a web browser in the code.

This is my very first code in VB 2010 so it might contain several errors.

Could anyone help me?

thanks in advance.
 

Latest posts

Back
Top