vb.net 教程 12-4 msHtml 3

版权声明:本文为博主原创文章,转载请在显著位置标明本文出处以及作者网名,未经作者允许不得用于商业目的。

相比之前学习的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教程 目录

 
————————————————
版权声明:本文为CSDN博主「VB.Net」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值