从网页获取所有html元素

时间:2017-06-29 18:09:06

标签: vb.net

我开始创建一个新的应用程序来检测网页上的所有html元素,在这个例子中我使用雅虎

但我得到null异常 这是错误

System.NullReferenceException was unhandled
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=autoclic
StackTrace:
   at autoclic.Form1.Button1_Click(Object sender, EventArgs e) in 
c:\users\monchique discovery\documents\visual studio 
2012\Projects\autoclic\autoclic\Form1.vb:line 7
I can not figure out how to solve this null exception 

这是我的代码

Public Class Form1

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Me.WebBrowser1.Navigate(New Uri("http://www.yahoo.com"))

    Me.ListBox1.Items.Add("Type" & "-->" & "Name")
    For Each element As HtmlElement In Me.WebBrowser1.document.All
        Me.ListBox1.Items.Add(element.TagName() & "-->" & element.Id)
    Next
    If Me.WebBrowser1.Document.All Is Nothing Then
        Return

    End If
End Sub
End Class

0 个答案:

没有答案