从字符串中提取一些html的最简单方法

本文关键字:html 最简单 方法 字符串 提取 | 更新日期: 2023-09-27 18:20:10

我有一个很长的HTML代码c#字符串,我想专门提取要点"<ul><li></li></ul>"。

假设我有以下HTML字符串。

var html = "<div class=ClassC441AA82DA8C5C23878D8>Here is a text that should be ignored.</div>This text should be ignored too<br><ul><li>*&nbsp;&nbsp;Need this one</li><li>Another bullet point I need</li><li>A bulletpoint again that I want</li><li>And this is the last bullet I want</li></ul><div>Ignore this line and text</div><p>Ignore this as well.</p>Text not important."

我需要"<ul>"到"</ul>"标记之间的所有内容。可以排除"<ul>"标记。

现在正则表达式不是我最强大的方面,但如果可以使用的话,我需要一些帮助。我的代码在c#中。

从字符串中提取一些html的最简单方法

您应该使用HtmlAgilityPack来完成这样的操作。我不久前写了一个小介绍,可能会帮助你开始:http://colinmackay.scot/2011/03/22/a-quick-intro-to-the-html-agility-pack/