15-6-2022 13:30:32
HtmlDocument hdoc = new HtmlDocument();
hdoc.LoadHtml(inf.ContentHtml);
var imgs = hdoc.DocumentNode.Descendants("img");
int c = 0;
foreach (var item in imgs)
{
c++;
HtmlNode nd = (HtmlNode)item;
string _cls = "";
if(nd.Attributes["class"] != null) _cls = nd.Attributes["class"].Value;
if(nd.Attributes["class"] != null)
nd.Attributes["class"].Value = "img-responsive";
else
{
nd.Attributes.Append("class", "img-responsive");
}
}
inf.ContentHtml = hdoc.DocumentNode.OuterHtml;
Dùng HtmlAgilityPack