1

Is there any free/open source c# libraries to extract data from html?

Given the input below

<div style="...">
 text part 1
</div>
<div style="...">
 text part 2
</div>

I want the output to be:

text part 1 text part 2
The Mask
  • 16,429
  • 36
  • 107
  • 177
rovsen
  • 4,842
  • 5
  • 37
  • 59

2 Answers2

6

Yes, you can use HtmlAgilityPack to parse HTML using Xpath queries as if it were XML.

carla
  • 1,880
  • 1
  • 34
  • 41
Romias
  • 13,397
  • 7
  • 53
  • 81
4

you can use HtmlAgilitiPack very good library.

and then:

public string StripHTMLTags(string str)
        {
            StringBuilder pureText = new StringBuilder();
            HtmlDocument doc = new HtmlDocument();
            doc.LoadHtml(str);

            foreach (HtmlNode node in doc.DocumentNode.ChildNodes)
            {
                pureText.Append(node.InnerText);
            }

            return pureText.ToString();
        }
The Mask
  • 16,429
  • 36
  • 107
  • 177