c# HtmlParser 简单使用

string resoureHtml = "<ul><li><img src=‘123‘/></li><li><img src=‘456‘/></li></ul>";
        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= tag.GetAttribute("src");
                sb.AppendFormat("<img src=\"{0}\" data-value=\"{1}\"/>", src + "ti",src+"ti");
            }
            sb.Append("</li>");
        }

        var aaa = sb.ToString();

 

c# HtmlParser 简单使用

上一篇:C#作业补充(6)


下一篇:Atitit.c# .net 3.5 4.0 各个版本新特性战略规划总结