इम निम्न विधि का उपयोग कर निकालने के लिए पाठ के रूप एचटीएमएल:htmlagilitypack - स्क्रिप्ट और शैली को हटाएं?
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;
}
समस्या है कि मैं भी स्क्रिप्ट और स्टाइल टैग मिलता है।
मैं उन्हें कैसे बाहर निकाल सकता हूं?
के बारे में क्या एक इनलाइन शैली अर्थात
? मैं इसे OuterHtml में देखता हूं लेकिन सभी इनलाइन शैलियों को भी बाहर करना चाहता हूं। – Jeremy
'अगर (childNode.Attributes.Contains (" शैली ")) { childNode.Attributes.Remove (" शैली "); } अगर (childNode.Attributes.Contains ("वर्ग")) { childNode.Attributes.Remove ("वर्ग"); } ' – Jeremy