标签:
下载地址:http://htmlagilitypack.codeplex.com/
1.添加HtmlAgilityPack.dll引用(引用类using HtmlAgilityPack;)。
2.简单根据html中input的id获取value代码如下:
// 模拟用户请求 WebClient webClient = new WebClient(); webClient.Encoding = System.Text.Encoding.UTF8; string htmlContext = webClient.DownloadString("http://stone_w.cnblogs.com/"); webClient.Credentials = CredentialCache.DefaultCredentials; // 添加授权证书 webClient.Headers.Add("User-Agent", "Microsoft Internet Explorer"); webClient.Headers.Add("Host", "www.cnblogs.com"); // 获取html元素(htmlContext为html页面字符串) HtmlDocument htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(htmlContext); // 加载html页面 HtmlNode navNode = htmlDoc.GetElementbyId("id名称"); Response.Write(navNode.Attributes["value"].Value);
处理html页面元素工具类(HtmlAgilityPack.dll)的使用
标签:
原文地址:http://www.cnblogs.com/libaoli/p/5051139.html