如何获取RSS订阅源的文章数量?

3
在C#、.NET 3.5中的Windows Forms应用程序中,如何获取给定RSS URL返回的项目数量的整数计数?
例如: 对于我的博客:http://forgefx.blogspot.com/feeds/posts/default 预期结果应为:postCount = 25
谢谢!

你需要页面大小还是总项目数? - Tanveer Badar
1个回答

2
using System.ServiceModel.Syndication;
using System.Linq;
class Program
{
    static void Main()
    {
        using(XmlReader source = XmlReader.Create(
                 "http://forgefx.blogspot.com/feeds/posts/default")) {
            int count = SyndicationFeed.Load(source).Items.Count();
        }
    }
}

(需要引用System.ServiceModel.Web.dll)

使用SyndicationFeed的优点在于同时支持RSS和Atom。


我怀疑这根本行不通。如果源代码实现了分页,你只能得到页面大小作为结果。 - Tanveer Badar
如果不进行额外的处理,这将无法正常工作,因为SyndicationFeed.Items返回一个IEnumerable而不是一个Collection - Ehtesh Choudhury

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接