在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