如何使用C#清洁的HTML标签 [英] How to clean HTML tags using C#
本文介绍了如何使用C#清洁的HTML标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如:
< HTML的xmlns =http://www.w3.org/1999/xhtmlXML:LANG =ENLANG =ENGT&;
< HEAD>
<标题>标题< /标题>
< /头>
<身体GT;
&所述; A HREF =?aaa.asp ID = 1>我要得到这个文字< / A>
< DIV>
< H1>这是我想要!< / H1>
< B>这是我想要!< / B>
< / DIV>
< /身体GT;
< / HTML>
和其结果是:
我要得到这个文本
这是我想要!
这是我想要!
解决方案
的HTMLDocument DOC =新的HTMLDocument();
doc.LoadHtml(HTML);
字符串s = doc.DocumentNode.SelectSingleNode(//机构)的InnerText。
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!!!
解决方案
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(html);
string s = doc.DocumentNode.SelectSingleNode("//body").InnerText;
这篇关于如何使用C#清洁的HTML标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文