FeedReader .NET Library

repository·master·Indexed 43 days ago

https://github.com/arminreiter/feedreader

A .NET library for reading and parsing RSS (0.91, 0.92, 1.0, 2.0) and ATOM feed formats. Features include asynchronous fetching via ReadAsync, HTML page parsing to extract feed URLs via GetFeedUrlsFromUrl, and support for version-specific properties through SpecificFeed.

Tokens
896
Snippets
4
Records
4
Agent score
6%

What's inside FeedReader

  1. Install FeedReader via NuGet

    master

    FeedReader is a .NET library for reading and parsing RSS and ATOM feeds. It supports RSS 0.91, 0.92, 1.0, 2.0, and ATOM formats. You can install it as a NuGet package.

    https://www.nuget.org/packages/CodeHollow.FeedReader/
  2. Read and parse a feed with ReadAsync

    master

    Use FeedReader.ReadAsync(url) to asynchronously fetch and parse a feed. The returned object provides common properties like Title, Description, ImageUrl, and a collection of Items.

    var feed = await FeedReader.ReadAsync("https://arminreiter.com/feed");
    
    Console.WriteLine("Feed Title: " + feed.Title);
    Console.WriteLine("Feed Description: " + feed.Description);
    Console.WriteLine("Feed Image: " + feed.ImageUrl);
    // ...
    foreach(var item in feed.Items)
    {
        Console.WriteLine(item.Title + " - " + item.Link);
    }
  3. Extract feed URLs from an HTML webpage

    master

    If you only have a website URL and not the direct feed URL, use FeedReader.GetFeedUrlsFromUrl(url) to parse the HTML page and find available feed links.

    string url = "arminreiter.com";
    var urls = FeedReader.GetFeedUrlsFromUrl(url);
                
    string feedUrl;
    if (urls.Count() < 1) // no url - probably the url is already the right feed url
        feedUrl = url;
    else if (urls.Count() == 1)
        feedUrl = urls.First().Url;
    else if (urls.Count() == 2) // if 2 urls, then its usually a feed and a comments feed, so take the first per default
        feedUrl = urls.First().Url;
    else
    {
        // show all urls and let the user select (or take the first or ...)
        // ...
    }
    
    var readerTask = FeedReader.ReadAsync(feedUrl);
    readerTask.ConfigureAwait(false);
    
    foreach (var item in readerTask.Result.Items)
    {
        Console.WriteLine(item.Title + " - " + item.Link);
        // ...
    }
  4. Access RSS 2.0 specific properties via SpecificFeed

    master

    Some properties are specific to certain feed versions (e.g., RSS 2.0). To access these, check the Type property and cast the SpecificFeed property to the appropriate type, such as Feeds.Rss20Feed.

    var feed = await FeedReader.ReadAsync("https://arminreiter.com/feed");
    
    Console.WriteLine("Feed Title: " + feed.Title);
                
    if(feed.Type == FeedType.Rss_2_0)
    {
        var rss20feed = (Feeds.Rss20Feed)feed.SpecificFeed;
        Console.WriteLine("Generator: " + rss20feed.Generator);
    }