gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 22:05:18 25 4
gpt4 key购买 nike

我正在使用 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

}

最佳答案

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

// Get rid of the tags
description = Regex.Replace(description, @"<.+?>", String.Empty);

// Then decode the HTML entities
description = WebUtility.HtmlDecode(description);

关于c# - SyndicationFeed - 项目摘要(RSS 描述) - 从中​​仅提取文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24488430/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com