首页 > 代码库 > c# HtmlParser 简单使用

c# HtmlParser 简单使用

string resoureHtml = "<ul><li><img src=http://www.mamicode.com/‘123‘/>
  • "; Lexer lexer = new Lexer(resoureHtml); Parser parser = new Parser(lexer); //获取UL标签 string tagName = "ul"; NodeFilter filter = new TagNameFilter(tagName); StringBuilder sb = new StringBuilder(); NodeList nodeList = parser.Parse(filter); var lis = nodeList[0].Children; for (int i = 0; i < lis.Count; i++) { var li = lis[i]; sb.Append("<li>"); var img = li.Children; for (int j = 0; j < img.Count; j++) { var tag = (ImageTag)img[0]; var src= http://www.mamicode.com/tag.GetAttribute("src"); sb.AppendFormat("<img src=http://www.mamicode.com/"{0}\" data-value=http://www.mamicode.com/"{1}\"/>", src + "ti",src+"ti"); } sb.Append("</li>"); } var aaa = sb.ToString();

     

    c# HtmlParser 简单使用