VB.NET - HTMLDocument to string

duyen

New Member
Reaction score
214
I would like to convert an HTMLDocument to a string, then run some functions on the string, then convert it back to HTMLDocument. How would I go about doing this?

Note: I know how to convert it back.
 

Samuraid

Advisor
Reaction score
81
If HTMLDocument is derived from a normal Object, just call the ToString() method on it. :p
 

duyen

New Member
Reaction score
214
Hmm I tried this:

PHP:
        Dim unclean As HtmlDocument = MyWebBrowser.Document
        Dim clean As String = unclean.ToString
        Dim bad1 As String = "target='_blank'"
        Dim bad2 As String = "target=""_blank"""
        If clean.Contains(bad1) Or clean.Contains(bad2) Then
            clean = clean.Replace(clean, bad1)
            clean = clean.Replace(clean, bad2)
        End If
        Me.MyWebBrowser.DocumentText = clean

But when I run that on any web page it outputs this in the browser:

System.Windows.Forms.HtmlDocument

I'm trying to remove all "target='_blank'" from the HTML code, then redisplay it without that part. Any suggestions?
 

holy_spirit

New Member
Reaction score
25
PHP:
/*In order to get back all html content in a webbrowser*/
Dim contents As String = WebBrowser1.DocumentText
/*Your code
.
.
.
.


NOTE : using to string not always returns the inner text of the specific object
It returns the type, namespace of the object by default*/
 

duyen

New Member
Reaction score
214
PHP:
/*In order to get back all html content in a webbrowser*/
Dim contents As String = WebBrowser1.DocumentText
/*Your code
.
.
.
.


NOTE : using to string not always returns the inner text of the specific object
It returns the type, namespace of the object by default*/

Outputs all the text on the page, and some bits and pieces of code. The only HTML actually parsed is the <b> tags...

???

Code:

PHP:
        Dim clean As String = MyWebBrowser.DocumentText
        Dim bad1 As String = "target='_blank'"
        Dim bad2 As String = "target=""_blank"""
        If clean.Contains(bad1) Or clean.Contains(bad2) Then
            clean = clean.Replace(" ", bad1)
            clean = clean.Replace(" ", bad2)
        End If
        Me.MyWebBrowser.DocumentText = clean
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top