1. import
Imports HtmlAgilityPack
2.判斷標籤有幾個
Dim countnode1 As Integer = htmlDoc.DocumentNode.SelectNodes(".//table").Count - 1
3.一個收尋網頁關鍵字的判斷
Friend Sub HTMLPrint() Dim webClient As New System.Net.WebClient Dim WebSource As String = webClient.DownloadString("http://www.google.com.tw/search?hl=zh-TW&q=" & TextBox1.Text) webClient.Encoding = Encoding.Unicode Dim links As New List(Of String)() Dim htmlDoc As New HtmlAgilityPack.HtmlDocument() Dim for_use As Integer = 0 htmlDoc.LoadHtml(WebSource) Try TextBox2.Text = "" Dim countnode1 As Integer = htmlDoc.DocumentNode.SelectNodes(".//table").Count - 1 Label1.Text = countnode1 For for_use = 1 To countnode1 Dim node01 As HtmlNodeCollection = htmlDoc.DocumentNode.SelectNodes("/html[1]/body[1]/table[1]/tbody[1]/tr[1]/td[2]/div[1]/div[3]/table[1]/tr[" & for_use & "]/td[1]") For Each link As HtmlNode In node01 'TextBox2.Text = TextBox2.Text & link.InnerText & Environment.NewLine 'TextBox2.Text = TextBox2.Text & "," & link.InnerText & Environment.NewLine TextBox2.Text = TextBox2.Text & link.InnerText & "," Next Dim node02 As HtmlNodeCollection = htmlDoc.DocumentNode.SelectNodes("/html[1]/body[1]/table[1]/tbody[1]/tr[1]/td[2]/div[1]/div[3]/table[1]/tr[" & for_use & "]/td[2]") For Each link As HtmlNode In node02 ' TextBox2.Text = TextBox2.Text & link.InnerText & Environment.NewLine 'TextBox2.Text = TextBox2.Text & "," & link.InnerText & Environment.NewLine TextBox2.Text = TextBox2.Text & link.InnerText & "," Next Next Catch ex As Exception ' MessageBox.Show("沒有相關關鍵字") ' TextBox2.Text = "" End Try End Sub
文章標籤
全站熱搜
留言列表