尝试获取锚标记

时间:2016-10-04 05:58:58

标签: .net vb.net xpath html-agility-pack

我正在尝试获取锚标记,但我得到运行时错误,这是我的代码

      Dim html1 As String = WebControl1.ExecuteJavascriptWithResult("document.getElementsByTagName('html')[0].innerHTML")
    Dim doc1 As New HtmlDocument
    doc1.LoadHtml(html1)
    WaitForPageLoad()
    Dim node As HtmlNodeCollection = doc1.DocumentNode.SelectNodes("//a")
    WaitForPageLoad()
    For Each links As HtmlNode In node
        If links.Attributes("href").Value = TextBox2.Text Then
            WebControl1.ExecuteJavascriptWithResult("")
            Application.DoEvents()
            WaitForPageLoad()
        End If

    Next

我不知道我哪里出错了

1 个答案:

答案 0 :(得分:0)

如果agelinks.Attributes("href"),那么就没有Nothing属性。

您可以使用null-conditional operator .Value

来避免此问题
?.