大家好,又见面了,我是你们的朋友全栈君。
版权声明:本文为博主原创文章,转载请在显著位置标明本文出处以及作者网名,未经作者允许不得用于商业目的。
相比之前学习的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 教程 目录
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/126813.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...