功能:1、轻松获取指元素HTML元素。2、可以根据属性标签进行筛选3、返回的都是Llist强类型无需转换 用过XElement的都知道 用来解析所以我就写了这么一个类似XElement的 XHTMLElement 用法: string filePath = ...
功能:
1、轻松获取指元素HTML元素。
2、可以根据属性标签进行筛选
3、返回的都是Llist强类型无需转换
用过XElement的都知道 用来解析
所以我就写了这么一个类似XElement的 XHTMLElement
用法:
get='_blank'>string filePath = Server.MapPath("~/file/test.htm"); //获取HTML代码 string mailBody = FileHelper.FileToString(filePath); XHtmlElement xh = new XHtmlElement(mailBody); //获取body的子集a标签并且 var link = xh.Descendants("body").ChildDescendants("a").Where(c => c.Attributes.Any(a => a.Key == "class" && a.Value == "icon")).ToList(); //获取带href的a元素 var links = xh.Descendants("a").Where(c => c.Attributes.Any(a => a.Key == "href")).ToList(); foreach (var r in links) { Response.Write(r.Attributes.Single(c => c.Key == "href").Value); //出输href } //获取第一个img var img = xh.Descendants("img"); //获取最近的第一个p元素以及与他同一级的其它p元素 var ps = xh.Descendants("p");
原标题:HTML解析类 ,让你不使用正则也能轻松获取HTML相关元素
关键词:HTML
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。