下面的代碼這是網上找的清理html冗余代碼,運行沒問題也能達到效果,但是想將特定標簽的特定屬性保留,比如a標簽保留href屬性,img標簽保留src、width、height、alt屬性,td和th標簽保留colspan、rowspan屬性等。
另外還想用正則把所有div標簽替換為p標簽。還請各位大神出手相救。
public static string ClearElement(string str, string element)
{
string old = @"<" + element + "[^>]+>";
string rep = "<" + element + ">";
str = Regex.Replace(str, old, rep, RegexOptions.IgnoreCase);
return str;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/229608.html
標籤:C#
上一篇:Linux中安裝gcc出現All mirror URLs are not using ftp,http[s] or file
