Вы можете сделать это, используя класс HtmlDocument
:
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(input);
doc.DocumentNode.SelectNodes("//style|//script").ToList().ForEach(n => n.Remove());
Для.NET Core 3.0, обновите класс Startup.cs как показано ниже.
public void ConfigureServices(IServiceCollection services)
{
...
services.AddControllers()
.AddNewtonsoftJson(
options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
);
...
}
См.: https://devblogs.microsoft.com/aspnet/asp-net-core-updates-in-net-core-3-0-preview-5 /