题
我如何可以获得饲料网址(RSS或原子)从博客网址 例如:- http://anirudhagupta.blogspot.com/ 所以我怎么可以得到他饲料的动态c#
我说,怎么我能得到博客的hostingconfiguration通过使用Regex和c#
解决方案
在RSS订阅能与你特别想看看会发生变化,但对于BlogSpot的它通常是
BLOGNAME /馈送/帖/默认 即。 http://anirudhagupta.blogspot.com/feeds/posts/default
如果你使用VS 2008中,你可以使用SyndicationFeed对象读取RSS和ATOM供稿。 (我想这是你想要当你说“动态获取他的饲料”做什么)
XmlReader reader = XmlReader.Create(feedUriString);
SyndicationFeed feed = SyndicationFeed.Load(reader);
foreach (SyndicationItem item in feed.Items)
{
//your code for rendering each item
}
http://msdn.microsoft.com/en -us /库/ system.servicemodel.syndication.aspx HTTP://jimleonardo.blogspot。 COM / 2009/02 / jimleocom-是-后备-一些知识-to.html
其他提示
当您访问该网站的根页,即。 http://myblog.com/ 你应该在头部发现一个链接属性,是这样的:
<link rel="alternate" type="application/rss+xml" title="MyBlog RSS Feed" href="http://feeds.feedburner.com/MyBlog" />
现在,任何网站都保证有在头的链接,但如果他们想那个小的RSS标识在Firefox或Internet Explorer显示当用户访问他们的网站,他们可能已经加入该行。 WordPress的默认完成了它。
请注意:我的例子都只是虚构的例子,不是真实的网站。可是你看,你知道几个博客的来源,你应该看到这样的链接标签。
使用 WebRequest
读数据,并从 Headers
你会知道的内容类型,如果 content-type
是 text/xml
, 你只是使用。阅读它,但是如果 content-type
是 text/html
, 你可能需要做更多的工作。
例如,地址是 http://myblog.com, ,不 http://myblog.com/feed/ 你想要的。所以你需要找到rss地址从默认主页的链接标签,链接标签是这样的:
<link rel="alternate" type="application/rss+xml" title="RSS" href="/rss"/ >
找到rss链接,可以使用 Microsoft HTML Object Library
, ,获得的链接标签,然后使用 obj.getAttribute("href")
法获得相对的地址。