Search code examples
vb.netwebmshtml

mshtml HTMLDocument createDocumentFromUrl in vb.net


How to use createDocumentFromUrl in vb.net. I got information like we should use IPersistStreamInit interface if we want to work on this. So i want an example showing this.


Solution

  • I would not recomend going alone into that interface, But I am guessing that you are doing this in a dll/cmd line so you can't use the winform solution so you can use htmlAgility pack and you can download it as a nuget HtmlAgilityPack

    But If you have to go the interop way you can check out this question Getting the HTML source from a WPF-WebBrowser-Control using IPersistStreamInit

    And the only thing you need to add for vb is this

      Public Overloads Sub Dispose() Implements IDisposable.Dispose
         Dispose()
         GC.SuppressFinalize(Me)
      End Sub
    

    But using the agility pack you can do it like this:

        Imports System.Collections.Generic
        Imports System.Linq
        Imports System.Text
        Imports System.Net
        Imports System.IO
        Imports HtmlAgilityPack
    
    
        Class Program
            Private Shared Sub Main(args As String())
                Dim wc As New WebClient()
                Dim doc As New HtmlDocument()
                doc.Load(wc.OpenRead("http://google.com"))
            End Sub
        End Class