SyndicationFeed -项目摘要(RSS描述)-仅从中提取文本

本文关键字:提取 取文本 RSS 项目 SyndicationFeed 描述 | 更新日期: 2023-09-27 18:10:51

我使用SyndicationFeed类来消费一些文章的rss提要。我想知道如何只从项目的摘要字段中获取文本,而不使用html标记。例如,有时(并非总是)它包含HTML标签,如:div, img, h, p tags:/a>/div>,img src='http"

我想去掉所有的标签。此外,我不确定它是否会在RSS提要中提供完整的描述。

我应该使用正则表达式处理这个问题吗?其他方法吗?

XmlReader reader = XmlReader.Create(response.GetResponseStream());
SyndicationFeed feed = SyndicationFeed.Load(reader);
foreach (SyndicationItem item in feed.Items)
{
     string description= item.Summary;  //This contains tags and not only the article text
}

SyndicationFeed -项目摘要(RSS描述)-仅从中提取文本

是的,我想正则表达式是实现这一目标的最简单的内置方法…

// Get rid of the tags
description = Regex.Replace(description, @"<.+?>", String.Empty);
// Then decode the HTML entities
description = WebUtility.HtmlDecode(description);