简体   繁体   中英

Library to extract data from html string

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

是的,您可以使用HtmlAgilityPack使用Xpath查询来解析HTML,就好像它是XML。

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 technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM