Modify HTML file in a c sharp class

后端 未结 4 885
Happy的楠姐
Happy的楠姐 2021-01-20 21:17

First of all my application is not a web application. My aim is reading html files and modify them.

So that I write this code:

    string fileName =         


        
4条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-20 22:01

    Install the HAP package:

    Install-Package HtmlAgilityPack -Version 1.11.27
    

    String:

    // From String
    string result ="
    "

    Code:

    var doc = new HtmlDocument();
    doc.LoadHtml(result);
    foreach (var node in doc.DocumentNode
    .Descendants("div")
    .Where(d => d.GetAttributeValue("Id", "RemoveableDiv").IndexOf("NavContent") >= 0)
    .ToArray())
    node.Remove();
    
    result = doc.documentnode.innerhtml;
    

提交回复
热议问题