Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8017513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:52:00+00:00 2026-06-04T20:52:00+00:00

I am using the follow code to get all text from a page into

  • 0

I am using the follow code to get all text from a page into a List<string>

HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(content);

foreach (var script in doc.DocumentNode.Descendants("script").ToArray())
    script.Remove();

foreach (var style in doc.DocumentNode.Descendants("style").ToArray())
    style.Remove();

foreach (HtmlAgilityPack.HtmlNode node in doc.DocumentNode.SelectNodes("//text()"))
{
    string found = WebUtility.HtmlDecode(node.InnerText.Trim());
    if (found.Length > 2) // removes some unwanted strings
        query[item.Key].Add(found);
}
  • But some html is still going into the string such as </form> is
    there a better way to narrow this code so I get only the text of each
    tag and nothing else or I will have to still parse the results to
    remove <*> tags ?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T20:52:02+00:00Added an answer on June 4, 2026 at 8:52 pm

    This can be done rather easily using only functions included in the HAP.

    HtmlDocument doc = new HtmlWeb().Load("http://www.google.com");
    List<string> words = doc.DocumentNode.DescendantNodes()
            .Where(n => n.NodeType == HtmlNodeType.Text
              && !string.IsNullOrWhiteSpace(HtmlEntity.DeEntitize(n.InnerText))
              && n.ParentNode.Name != "style" && n.ParentNode.Name != "script")
            .Select(n => HtmlEntity.DeEntitize(n.InnerText).Trim())
            .Where(s => s.Length > 2).ToList();
    

    The result is a list of words with a length of more than 2 and everything already escaped, so no need for WebUtility.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the follow code that downloads a file from internet using Indy components: procedure
I need any source code by which I can follow an account using MGTwitterEngine.
I am using Jquery to get googlemap data and load it into a div.
Hi i all having a requirement to delete particular data from a text file.
I have implemented Tabbar in sencha touch without any content as follows: using code
I'm using this plugin: http://www.jeremymartin.name/projects.php?project=kwicks And my code follows this example: http://www.jeremymartin.name/examples/kwicks.php?example=7 I'm using
I am using the library ICSharpCode.SharpZipLib.Zip ; My code is follows: The path is
I am using silverlight, My code is set up for a usercontrol as follows:
I am using Tomcat 6 and Postgresql 8.4. My code looks as follows: try
I am using VBA for Microsoft Excel 2007. My code is as follows: Sub

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.