Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
238 views
in Technique[技术] by (71.8m points)

How to clean HTML tags using C#

For example:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>title</title>
</head>
<body>
    <a href="aaa.asp?id=1"> I want to get this text </a>
    <div>
        <h1>this is my want!!</h1>
        <b>this is my want!!!</b>
    </div>
</body>
</html>

and the result is:

 I want to get this text 
this is my want!!
this is my want!!!
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

HTML Agility Pack:

    HtmlDocument doc = new HtmlDocument();
    doc.LoadHtml(html);
    string s = doc.DocumentNode.SelectSingleNode("//body").InnerText;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...