Im utilizzando il seguente metodo per estrarre forma di testo HTML:htmlagilitypack - rimuovi script e stile?
public string getAllText(string _html)
{
string _allText = "";
try
{
HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();
document.LoadHtml(_html);
var root = document.DocumentNode;
var sb = new StringBuilder();
foreach (var node in root.DescendantNodesAndSelf())
{
if (!node.HasChildNodes)
{
string text = node.InnerText;
if (!string.IsNullOrEmpty(text))
sb.AppendLine(text.Trim());
}
}
_allText = sb.ToString();
}
catch (Exception)
{
}
_allText = System.Web.HttpUtility.HtmlDecode(_allText);
return _allText;
}
problema è che anche ottenere script e style tags.
Come posso escluderli?
Che dire di uno stile in linea cioè
? Lo vedo in OuterHtml, ma vorrei eliminare anche tutti gli stili in linea. – Jeremy
'if (childNode.Attributes.Contains (" stile ")) { childNode.Attributes.Remove (" stile "); } if (childNode.Attributes.Contains ("class")) { childNode.Attributes.Remove ("classe"); } ' – Jeremy