How to transform a string type variable that contains the retrieval of an HTML into an Html Document without passing it through the Webbrowser? on VB.net

Pedro Requena 21 Reputation points
2021-07-01T00:01:05.497+00:00

I am working with querying elements from various websites and I am using Chromium from Webview and I get all the Html modified by the Javascript and I need to load that Text from the retrieved Html into an HTML Document and the way I do it is by doing this:

Public Sub Descarga_Html1()

    Dim IE_Webbrowser As New WebBrowser
    Dim Contenido_HTMl As String
    Contenido_HTMl = Form2.WebView1.GetSource.ToString

    'Dim htmldoc As HtmlDocument

    Dim Datos As String
    Datos = Contenido_HTMl

    IE_Webbrowser.ScriptErrorsSuppressed = True
    IE_Webbrowser.DocumentText = Datos
    IE_Webbrowser.Document.OpenNew(True)
    IE_Webbrowser.Document.Write(Datos)

    Espera(2000)
    Htmldoc = IE_Webbrowser.Document
    IE_Webbrowser.DocumentStream.Close()
    IE_Webbrowser.Dispose()

end sub
but doing it this way leads me to Error:

System.OutOfMemoryException

From the amount of queries and the load of the Webbrowser, for that reason I would like to have the idea of how to pass that Text that contains the HTML directly to an HTML Document, thank you very much.

Developer technologies Visual Studio Other
0 comments No comments
{count} votes

Accepted answer
  1. Sam of Simple Samples 5,546 Reputation points
    2021-07-01T00:48:44.713+00:00

    As best as I can tell, you are trying to use WebBrowser and WebView as if they are the same thing. They are not. You cannot use parts of WebBrowser and parts of WebView.

    See WebView Class; specifically the part that says:

    In apps compiled for Windows 10, WebView uses the Microsoft Edge rendering engine to display HTML content. In apps compiled for Windows 8 or Windows 8.1, WebView uses Internet Explorer 11 in document mode.

    As you can see, for WebView there is no equivalent to a WebBrowser.Document property. The following describes how to get the HTML from a WebView, however they are for UWP programs. You should have used a tag for your question to indicate whether this is a UWP, WPF or Windows Forms program.

    If you can be more specific about the type of application this is then I can be more specific about what to do.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Pedro Requena 21 Reputation points
    2021-07-01T01:02:09.61+00:00

    It is an Application in Windows Form of desktop type I use the EO.Webview chromium in .Net (vb.net) registered in a windows form with the GETHTML property extracted all the code of the HTML transformed by the execution of the Javascript and that Html String obtained by the Gethtml is the one I need to convert into Html Document

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.