加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

vb.net 教程 12-4 msHtml 3

发布时间:2020-12-17 08:13:43 所属栏目:百科 来源:网络整理
导读:相比之前学习的HtmlDocument类和HtmlElement类,mshtml还提供了网页元素更详细的分类,比如 IHTMLScriptElement :脚本元素 IHTMLStyleSheet :样式表 IHTMLFormElement:表单元素 等等 这些不同的元素分类有着自己的特殊属性和方法。 获得脚本信息: Private
相比之前学习的HtmlDocument类和HtmlElement类,mshtml还提供了网页元素更详细的分类,比如
IHTMLScriptElement :脚本元素
IHTMLStyleSheet :样式表
IHTMLFormElement:表单元素
等等
这些不同的元素分类有着自己的特殊属性和方法。

获得脚本信息:
    Private Sub Button3_Click(sender As Object,e As EventArgs) Handles Button3.Click
        Dim doc As mshtml.IHTMLDocument
        doc = wbMain.Document.DomDocument
        Dim scrs As mshtml.IHTMLElementCollection = doc.scripts
        Dim scr As mshtml.IHTMLScriptElement

        For i As Integer = 0 To scrs.length - 1
            scr = CType(scrs.item(i),mshtml.IHTMLScriptElement)
            txtInfo.Text &= "htmlFor:" & scr.htmlFor & vbCrLf
            txtInfo.Text &= "event:" & scr.event & vbCrLf
            txtInfo.Text &= "src:" & scr.src & vbCrLf
            txtInfo.Text &= "text:" & scr.text & vbCrLf
            txtInfo.Text &= "type:" & scr.type & vbCrLf
            txtInfo.Text &= "====================" & vbCrLf
        Next

    End Sub
运行如下:
获得样式表信息:
    Private Sub Button4_Click(sender As Object,e As EventArgs) Handles Button4.Click
        Dim doc As mshtml.IHTMLDocument2
        doc = wbMain.Document.DomDocument
        Dim styles As mshtml.HTMLStyleSheetsCollection = doc.styleSheets
        Dim style As mshtml.IHTMLStyleSheet
        For i As Integer = 0 To styles.length - 1
            style = CType(styles.item(i),mshtml.IHTMLStyleSheet)
            txtInfo.Text &= "cssText:" & style.cssText & vbCrLf
            txtInfo.Text &= "href:" & style.href & vbCrLf
            txtInfo.Text &= "id:" & style.id & vbCrLf
            txtInfo.Text &= "title:" & style.title & vbCrLf
            txtInfo.Text &= "type:" & style.type & vbCrLf
            txtInfo.Text &= "====================" & vbCrLf
        Next

    End Sub
运行如下:
获得表单信息:
    Private Sub Button5_Click(sender As Object,e As EventArgs) Handles Button5.Click
        Dim doc As mshtml.HTMLDocument
        doc = wbMain.Document.DomDocument

        doc.sc
        Dim eles As mshtml.IHTMLElementCollection = doc.forms
        Dim frm As mshtml.IHTMLFormElement
        For i As Integer = 0 To eles.length - 1
            frm = CType(eles.item(i),mshtml.IHTMLFormElement)

            txtInfo.Text &= "action:" & frm.action & vbCrLf
            txtInfo.Text &= "encoding:" & frm.encoding & vbCrLf
            txtInfo.Text &= "method:" & frm.method & vbCrLf
            txtInfo.Text &= "name:" & frm.name & vbCrLf
            txtInfo.Text &= "target:" & frm.target & vbCrLf
            txtInfo.Text &= "====================" & vbCrLf
        Next
    End Sub
运行如下:

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读