【问题标题】:Extracting HTML text提取 HTML 文本
【发布时间】:2012-08-14 17:10:06
【问题描述】:

我正在解决一个问题。我将提取 som HTML 文本并将它们存储为 Anchor 对象。例如:

<html>
<head>
<title>{dynamihead/}</title>
</head>

<body>
{repeatinghtml}
<p>{repeatinganchor1/}</p>
<p>{repeatinganchor2/}</p>
<p>{repeatinganchor3/}</p>
<p>{repeatinganchor4/}</p>
{/repeatinghtml}
</body>
</html>

我想提取 {} 锚点。如果它是一个自我终止的 achour,我想创建 {dynamihead/} 只是这个锚对象。但是如果它包含 childAnchours 我想提取像

{repeatinghtml}
    <p>{repeatinganchor1/}</p>
    <p>{repeatinganchor2/}</p>
    <p>{repeatinganchor3/}</p>
    <p>{repeatinganchor4/}</p>
{/repeatinghtml}

我想提取所有子锚点并将其放入主锚点的集合中。我已经拒绝了 Anchor 类,但我在字符串处理方面不太熟练,所以我无法提取我想要的文本。这是一个 Winform 应用程序,它将加载模板 HMLT 文件,对其进行处理并将信息插入到 ancours 中并发送电子邮件 i html 格式。

【问题讨论】:

  • 我认为你可以使用Regex来提取字符串或XDocument

标签: c# html


【解决方案1】:

尝试查看HtmlAgility 库。即使乍一看很简单,但有一个lot of reasons to avoid using regex for such problems,八个字符串操作可能还不够。

【讨论】:

  • 我尝试过使用 HtmlAgility 库,但没有任何运气。也许我用错了,但我试图按照一些例子没有运气。
猜你喜欢
  • 2018-10-23
  • 2020-07-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-26
  • 2012-04-20
  • 1970-01-01
  • 2023-03-04
相关资源
最近更新 更多