在Windows Forms应用程序中的C#,.NET 3.5 ...如何获取RSS提要项目数量?
如何得到给定RSS url返回的项数的整数数?
例子: 对于我的博客:http://forgefx.blogspot.com/feeds/posts/default
预期的结果将是:postCount = 25个
谢谢!
在Windows Forms应用程序中的C#,.NET 3.5 ...如何获取RSS提要项目数量?
如何得到给定RSS url返回的项数的整数数?
例子: 对于我的博客:http://forgefx.blogspot.com/feeds/posts/default
预期的结果将是:postCount = 25个
谢谢!
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在同一时间。
我怀疑这会起作用。如果源代码实现分页,那么只会得到页面大小。 – 2016-10-11 13:42:19
因为[SyndicationFeed.Items](https://msdn.microsoft.com/en-us/library/system.servicemodel.syndication.syndicationfeed.items.aspx)返回一个'IEnumerable '而不是'收藏品'。 – 2017-01-31 20:54:03
需要页面尺寸或总项目? – 2016-10-11 13:42:40