版权声明:本文为博主原创文章,转载请在显著位置标明本文出处以及作者网名,未经作者允许不得用于商业目的。
继续获得更多的网页信息:
获得网页上所有图片信息:
Private Sub btnImages_Click(sender As Object, e As EventArgs) Handles btnImages.Click
Dim htmlInfo As String = ""
Dim imgCount As Integer = 0
Dim imgs As HtmlElementCollection
imgs = wbMain.Document.Images
For Each img As HtmlElement In imgs
imgCount += 1
htmlInfo &= "图片" & imgCount & ": " & img.OuterHtml & ControlChars.CrLf
Next
txtInfo.Text = htmlInfo
End Sub
运行时如图:
获得网页上所有链接信息:
Private Sub btnLinks_Click(sender As Object, e As EventArgs) Handles btnLinks.Click
Dim htmlInfo As String = ""
Dim linkCount As Integer = 0
Dim lnks As HtmlElementCollection
lnks = wbMain.Document.Links
For Each lnk As HtmlElement In lnks
linkCount += 1
htmlInfo &= "链接" & linkCount & ": " & lnk.OuterHtml & ControlChars.CrLf
Next
txtInfo.Text = htmlInfo
End Sub
还可以通过All属性获得网页上的所有元素:
Private Sub btnAllElement_Click(sender As Object, e As EventArgs) Handles btnAllElement.Click
Dim htmlInfo As String = ""
Dim htmlAlls As HtmlElementCollection
htmlAlls = wbMain.Document.All
For Each htmlSingle As HtmlElement In htmlAlls
htmlInfo &= htmlSingle.TagName.ToUpper & ControlChars.CrLf
Next
txtInfo.Text = htmlInfo
End Sub
以上代码用到了HtmlElement类,相关知识请参看下一节教程。
由于.net平台下C#和vb.NET很相似,本文也可以为C#爱好者提供参考。
学习更多vb.net知识,请参看vb.net教程 目录
————————————————
版权声明:本文为CSDN博主「VB.Net」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。