如何使用HtmlAgility包获取表内的标题?

时间:2015-08-18 23:10:23

标签: vb.net html-agility-pack

您好我正在尝试从此表中获取“title”元素:

<td class="field_domain"><a href="/goto/1/f4gw3/52/?tr=search" target="_blank" rel="nofollow" title="PlantarFasciitisHeelPain.com"><strong>Plantar</strong><strong>Fasciitis</strong>HeelPain.com</a></td>

这是我的代码几乎可以工作但不完全:

Dim web As New HtmlAgilityPack.HtmlWeb()
        Dim htmlDoc As HtmlAgilityPack.HtmlDocument = web.Load("https://www.expireddomains.net/domain-name-search/?o=domainpop&r=d&q=plantar+fasciitis")
        Dim html As String = htmlDoc.DocumentNode.OuterHtml
        Dim tabletag = htmlDoc.DocumentNode.SelectNodes("//td[@class='field_domain']")


        For Each t In tabletag
            Dim var = t.SelectSingleNode("//td[@class='title']").InnerText
            MessageBox.Show(var)
        Next

1 个答案:

答案 0 :(得分:0)

这就是诀窍:

Dim web As New HtmlAgilityPack.HtmlWeb()
Dim htmlDoc As HtmlAgilityPack.HtmlDocument = web.Load("https://www.expireddomains.net/domain-name-search/?o=domainpop&r=d&q=plantar+fasciitis")
Dim html As String = htmlDoc.DocumentNode.OuterHtml

For Each linkItem As HtmlNode In htmlDoc.DocumentNode.SelectNodes("//td[@class='field_domain']")
    Dim name = linkItem.Element("a").InnerText
    MessageBox.Show(name)


Next