简体   繁体   English

如何从blogurl获取RSS或ATOM feed URL

[英]how to get RSS or ATOM feed url from blogurl

how i can get feed url (RSS Or ATOM) from blog url ex:- http://anirudhagupta.blogspot.com/ So how i can get his feed dynamically by c# 我如何从博客网址获取Feed网址(RSS或ATOM),例如:-http: //anirudhagupta.blogspot.com/因此,我如何通过c#动态获取他的Feed

i say that how i can get blog's feedurl by using Regex and c# 我说我如何使用Regex和C#获取博客的feedurl

When you visit the root page of the site, ie. 当您访问网站的根页面时,即 http://myblog.com/ you should find a link attribute in the head, something like: http://myblog.com/,您应该在标题中找到一个链接属性,例如:

<link rel="alternate" type="application/rss+xml" title="MyBlog RSS Feed" href="http://feeds.feedburner.com/MyBlog" />

Now, no site is guaranteed to have that link in the head, but if they want that little rss logo to show up in firefox or internet explorer when users visit their site, they probably have added that line. 现在,不能保证任何站点的头部都有该链接,但是如果用户希望在用户访问其站点时在firefox或Internet Explorer中显示该小rss徽标,则可能已添加了该行。 Wordpress does it by default. Wordpress默认情况下会这样做。

Note: My examples are just fictitious examples, not real sites. 注意:我的示例只是虚构的示例,不是真实的网站。 But just look at the source of a few blogs you know, and you should see a link tag like this. 但是,仅查看您知道的一些博客的来源,您应该会看到这样的链接标记。

The Rss feeds can vary with what you specifically want to look at, but for blogspot it's usually Rss提要可能会因您要查看的内容而异,但是对于Blogspot,通常

blogname /feeds/posts/default ie. 博客名称 / feeds / posts / default,即 http://anirudhagupta.blogspot.com/feeds/posts/default http://anirudhagupta.blogspot.com/feeds/posts/default

If you're using VS 2008, you can use the SyndicationFeed object to read both RSS and ATOM feeds. 如果使用的是VS 2008,则可以使用SyndicationFeed对象读取RSS和ATOM提要。 (I assume this is what you want to do when you say "get his feed dynamically") (我假设这是当您说“动态获取他的供稿”时要执行的操作)

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/library/system.servicemodel.syndication.aspx http://jimleonardo.blogspot.com/2009/02/jimleocom-is-back-up-some-how-to.html http://msdn.microsoft.com/zh-CN/library/system.servicemodel.syndication.aspx http://jimleonardo.blogspot.com/2009/02/jimleocom-is-back-up-some-how-to .html

Use WebRequest to read the data, and from the Headers you will know the content-type, if the content-type is text/xml , you just use XmlReader to read it, but if the content-type is text/html , you may need to do more work. 使用WebRequest读取数据,并且从Headers您将知道内容类型,如果content-typetext/xml ,则只需使用XmlReader读取它,但是如果content-typetext/html ,则可以需要做更多的工作。
For example, the address is http://myblog.com , not http://myblog.com/feed/ that you want. 例如,该地址是http://myblog.com ,而不是您想要的http://myblog.com/feed/ So you need find the rss address from the default page's link tag, the link tag is like this: 因此,您需要从默认页面的链接标签中找到rss地址,链接标签如下所示:
<link rel="alternate" type="application/rss+xml" title="RSS" href="/rss"/ >
To find the rss link, you can use Microsoft HTML Object Library , get the link tag, then use obj.getAttribute("href") method to get the relative address. 要找到rss链接,可以使用Microsoft HTML Object Library ,获取链接标记,然后使用obj.getAttribute("href")方法获取相对地址。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM