【问题标题】:Easiest way to extract some html from string [duplicate]从字符串中提取一些html的最简单方法[重复]
【发布时间】:2013-06-25 22:38:48
【问题描述】:

我有一长串 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."

我需要“&lt;ul&gt;”到“&lt;/ul&gt;”标签之间的所有内容。可以排除“&lt;ul&gt;”标签。

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

【问题讨论】:

标签: c# asp.net regex


【解决方案1】:

您应该将 HtmlAgilityPack 用于此类事情。前段时间我写了一个小介绍,可能对你有所帮助:http://colinmackay.scot/2011/03/22/a-quick-intro-to-the-html-agility-pack/

【讨论】:

    猜你喜欢
    • 2012-05-09
    • 1970-01-01
    • 2010-11-17
    • 1970-01-01
    • 1970-01-01
    • 2011-06-08
    • 2013-02-23
    • 2013-07-28
    • 2019-05-21
    相关资源
    最近更新 更多