Parsing HTML without Using the Browser Control | CodeGuru

Parsing HTML without Using the Browser Control

How to Use MS HTML as a HTML Parser in Visual Basic Without Using the Browser Control. . Environment: VB6 SP5, XPPro, IE6 The main goal of this article is to provide a way to use the HTML parser inside Microsoft Internet Explorer within your program. This is something usually easy if you use the […]

Written By
CodeGuru Staff
CodeGuru Staff
Oct 1, 2002
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

How to Use MS HTML as a HTML Parser in Visual Basic Without Using the Browser Control.

.

Environment: VB6 SP5, XPPro, IE6

The main goal of this article is to provide a way to use the HTML parser inside Microsoft Internet Explorer within your program.

This is something usually easy if you use the browser control. There are plenty of examples on the Internet, but when it comes to using it in a UI-less way, there is nothing done in Visual Basic. All examples I’ve seen are in Visual C++ using interfaces that are not available in Visual Basic.

After days of trying to find a way, trying the .NET platform to be able to use an HTML parser in a Windows NT service, I finally found a way. I don’t claim this is the nicest way to do it, but it works like a charm, and you have access to the DOM of the HTML document you want, which can be very useful if you’re looking to parse a HTML document.

Your code must have a reference to the Microsoft HTML Object Library. Internet Explorer 5 or more is required to do this. Simply copy this code in any function.

Dim objLink As HTMLLinkElement
Dim objMSHTML As New MSHTML.HTMLDocument
Dim objDocument As MSHTML.HTMLDocument
‘ This function is only available with Internet Explorer 5
Set objDocument = objMSHTML.createDocumentFromUrl(txtURL.Text, _
                                                  vbNullString)
‘ Tricky, to make the function wait for the document to
‘ complete, usually the transfer is asynchronous. Note
‘ that this string might be different if you have another
‘ language than English for Internet Explorer on the
‘ machine where the code is executed.
While objDocument.readyState <> “complete”
    DoEvents
Wend
‘ Source Code
Debug.Print = objDocument.documentElement.outerHTML
‘ Title
Debug.Print “Title : ” & objDocument.Title
‘ Link Collection
For Each objLink In objDocument.links
    lstLinks.AddItem objLink
    Debug.Print “Link:  ” & objLink
Next

Downloads

Download demo project – 3 Kb

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.