先引用HtmlAgilityPack.dll,沒有的話下載一下
直接上代碼
var doc = new HtmlDocument(); doc.LoadHtml(html);//html字符串 //獲取標簽里的值 var nodes = doc.DocumentNode.SelectSingleNode("//div[@class='list-container']").InnerText; //獲取一個多個節點,進行遍歷 var nodes_gjjl = doc_gjjl.DocumentNode.SelectNodes("//div[@class='project-follow']"); foreach (var item in nodes_gjjl) { string gjjl_time = item.SelectSingleNode("./table/tbody/tr[1]/td[2]/span").InnerText; }