using System.Text.RegularExpressions;
public static void Main()
var config = Configuration.Default.WithDefaultLoader();
var context = BrowsingContext.New(config);
var document = context.OpenAsync("https://avaloniaui.github.io/icons.html").Result;
var codeElements = document.QuerySelectorAll("code");
string outputPath = "output.html";
using (StreamWriter writer = new StreamWriter(outputPath))
foreach (var codeElement in codeElements)
string cleanText = RemoveHtmlTagsAndKeepContent(codeElement.InnerHtml);
cleanText = cleanText.Replace(";>",">");
cleanText = cleanText.Replace("<","<");
cleanText = cleanText.Replace(">",">");
Console.WriteLine(cleanText);
Console.WriteLine("所有<code>标签的内容已写入到文件中。");
static string RemoveHtmlTagsAndKeepContent(string input)
string pattern = @"<[^>]*>";
string cleanText = Regex.Replace(input, pattern, String.Empty);