HTML Agility Pack 提供了用XPath去分析 html的結構的功能
用於要抓網站資料的時候很有用
下面是用 HTML Agility Pack以Xpath的語法去抓yahoo股市資料的code
Xpath 的語法 可以參考XPath Tutorial
sample on MSDN
Download HTML Agility Pack
用於要抓網站資料的時候很有用
下面是用 HTML Agility Pack以Xpath的語法去抓yahoo股市資料的code
Dim client As New WebClient()
Dim sr As Stream = client.OpenRead("http://tw.stock.yahoo.com/q/q?s=2409")
Dim doc As New HtmlAgilityPack.HtmlDocument()
doc.Load(sr, System.Text.Encoding.GetEncoding("big5"))
Dim nodes As HtmlAgilityPack.HtmlNodeCollection = doc.DocumentNode.SelectNodes("/html/body/center/table[2]/tr/td/table/tr[2]/td")
If nodes IsNot Nothing Then
For Each node As HtmlAgilityPack.HtmlNode In nodes
Console.WriteLine(node.InnerText.Trim())
Next
End If
Console.ReadLine()
Xpath 的語法 可以參考XPath Tutorial
sample on MSDN
Download HTML Agility Pack
留言