如何从c#中的HTML解析文本 [英] How to parse the text out of html in c#

查看:107
本文介绍了如何从c#中的HTML解析文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 这是< h4>一些< / h4>文字+ Environment.NewLine + 
这是更多< h5>文本< / h5>

我只想提取文本,所以结果应该是

 这是一些文本+ Environment.NewLine + 
这是一些更多的文字

我该怎么做?

解决方案

使用 HtmlAgilityPack

  string html = @这是< h4>一些< / h4>文本+ Environment.NewLine + 
这是更多< h5>文本< / h5>;

HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(html);
var str = doc.DocumentNode.InnerText;


I have an html expression like this:

 "This is <h4>Some</h4> Text" + Environment.NewLine +
 "This is some more <h5>text</h5>

And I want only to extract the text. So the result should be

"This is Some Text" + Environment.NewLine +
 "This is some more text"

How do I do this?

解决方案

Use HtmlAgilityPack

string html = @"This is <h4>Some</h4> Text" + Environment.NewLine +
                "This is some more <h5>text</h5>";

HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(html);
var str = doc.DocumentNode.InnerText;

这篇关于如何从c#中的HTML解析文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆