Reputation:
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#
i say that how i can get blog's feedurl by using Regex and c#
Upvotes: 0
Views: 5108
Reputation: 4286
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.
For example, the address is http://myblog.com, not http://myblog.com/feed/ that you want. So you need find the rss address from the default page's link tag, the link tag is like this:
<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.
Upvotes: 0
Reputation: 936
When you visit the root page of the site, ie. http://myblog.com/ you should find a link attribute in the head, something like:
<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. Wordpress does it by default.
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.
Upvotes: 6
Reputation: 2327
The Rss feeds can vary with what you specifically want to look at, but for blogspot it's usually
blogname/feeds/posts/default ie. 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. (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
Upvotes: 3