vb.net 教程 12-2 HtmlDocument类 2

前端之家收集整理的这篇文章主要介绍了vb.net 教程 12-2 HtmlDocument类 2前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

从本节开始,将对HtmlDocument类的一些属性方法做讲解。


窗体设计界面如下:

转到按钮代码如下:

    Private Sub btnGoto_Click(sender As Object,e As EventArgs) Handles btnGoto.Click
        wbMain.Navigate(txtGotoUrl.Text)
    End Sub

当wbMain载入网页后,就可以获得网页相关信息了:

    Private Sub btnInfo_Click(sender As Object,e As EventArgs) Handles btnInfo.Click
        Dim htmlInfo As String = ""
        Dim document As HtmlDocument
        document = wbMain.Document

        htmlInfo &= "网页背景色:" & document.BackColor.ToString & ControlChars.CrLf
        htmlInfo &= "网页前景色:" & document.ForeColor.ToString & ControlChars.CrLf
        htmlInfo &= "网页标题:" & document.Title & ControlChars.CrLf
        htmlInfo &= "网址:" & document.Url.ToString & ControlChars.CrLf
        htmlInfo &= "Cookie:" & document.Cookie & ControlChars.CrLf
        htmlInfo &= "所在域:" & document.Domain & ControlChars.CrLf
        htmlInfo &= "网页编码:" & document.Encoding & ControlChars.CrLf
        htmlInfo &= "链接颜色:" & document.LinkColor.ToString & ControlChars.CrLf
        htmlInfo &= "链接访问颜色:" & document.VisitedLinkColor.ToString & ControlChars.CrLf

        txtInfo.Text = htmlInfo
    End Sub

运行时如下图:

这里用了我的网站来做说明


由于.net平台下C#和vb.NET很相似,本文也可以为C#爱好者提供参考。

学习更多vb.net知识,请参看 vb.net 教程 目录

猜你在找的VB相关文章