Im stosując następujące metody w celu uzyskania postaci tekstu html:htmlagilitypack - usunąć skrypt i styl?
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;
}
problem jest, że również uzyskać skryptów i stylów tagów.
Jak mogę je wykluczyć?
Co o stylu inline tj
? Widzę to w OuterHtml, ale chciałbym również usunąć wszystkie style śródliniowe. – Jeremy
'if (childNode.Attributes.Contains (" style ")) { childNode.Attributes.Remove (" style "); } if (childNode.Attributes.Contains ("class")) { childNode.Attributes.Remove ("class"); } ' – Jeremy