如何使我的vb.net应用程序仅显示网站上的文本并忽略源代码

时间:2017-12-01 11:29:17

标签: vb.net

如标题中所述,我试图让我的vb.net应用程序忽略源代码,只显示文本在网站上。我希望它忽略代码pre和/ code / pre 这是我的代码:

Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Dim Str As System.IO.Stream
        Dim srRead As System.IO.StreamReader
        Try
            Dim req As System.Net.WebRequest = System.Net.WebRequest.Create("http://junkcode.gehaxelt.in/")
            Dim resp As System.Net.WebResponse = req.GetResponse
            Str = resp.GetResponseStream
            srRead = New System.IO.StreamReader(Str)
            RichTextBox1.Text = srRead.ReadToEnd
        Catch ex As Exception
            RichTextBox1.Text = "Content Cannot Be Downloaded"
        Finally
            srRead.Close()
            Str.Close()
        End Try
    End Sub

    Private Sub VScrollBar1_Scroll(sender As Object, e As ScrollEventArgs) 

    End Sub
End Class

1 个答案:

答案 0 :(得分:0)

您可以将下载的HTML加载到HtmlDocument对象

Dim htmlDoc As HtmlDocument = new HtmlDocument()
htmlDoc.LoadHtml(srRead.ReadToEnd)

加载HtmlDocument后。您可以使用Body属性来访问Html正文。之后,您可以根据需要解析文档。

MSDN Reference