feedparser library – Read Web Feeds in XML, HTML, JSON, TXT and More; Build Your Own News Reader from Scratch in Twenty Lines

feedparser/feedparser: feedparser gem – (universal) web feed parser and normalizer (XML w/ Atom or RSS, JSON Feed, HTML w/ Microformats e.g. h-entry/h-feed or Feed.HTML, Feed.TXT w/ YAML, JSON or INI & Markdown, etc.)
https://github.com/feedparser/feedparser

feedparser
feedparser gem – web feed parser and normalizer (Atom, RSS, JSON Feed, HTML h-entry, etc.)

home :: github.com/feedparser/feedparser
bugs :: github.com/feedparser/feedparser/issues
gem :: rubygems.org/gems/feedparser
rdoc :: rubydoc.info/gems/feedparser
forum :: groups.google.com/group/wwwmake

1. What’s a web feed?

A web feed (or news feed) is a (simple) document/text format that:

(1) lets you publish a list of:

status updates, blog postings, articles, pictures, cartoons, recordings, etc.
and that

(2) lets others subscribe to your updates.

Example:

{
    "version": "https://jsonfeed.org/version/1",
    "title": "Jason Fried's Microblog",
    "home_page_url": "https://micro.blog/jasonfried/",
    "feed_url": "https://micro.blog/jasonfried/feed.json",
    "author": {
        "name": "Jason Fried",
        "url": "https://micro.blog/jasonfried/",
        "avatar": "https://micro.blog/jasonfried/avatar.png"
    },
    "items": [
        {
            "id": "865767227416612864",
            "url": "https://micro.blog/jasonfried/status/865767227416612864",
            "content_text": "JSON Feed? I know that guy.",
            "date_published": "2017-05-19T20:12:00-00:00"
        }
    ]
}

2. What’s the feedparser library?

One library to rule them all! All your base are blong to feedparser.

In the end all formats are just 0 and 1s or:

feed.title
feed.url
feed.items[0].title
feed.items[0].url
feed.items[0].published
feed.items[0].content_html or feed.items[0].content
feed.items[0].content_text
feed.items[0].summary
etc.

3. Let your computer handle the reading of web feeds ;-).

Read Feed Example

require 'open-uri'
require 'feedparser'

txt = open( 'http://openfootball.github.io/feed.xml' ).read

feed = FeedParser::Parser.parse( txt )

puts feed.title
# => "football.db - Open Football Data"

puts feed.url
# => "http://openfootball.github.io/"

puts feed.items[0].title
# => "football.db - League Quick Starter Sample - Mauritius Premier League - Create Your Own Repo/League(s) from Scratch"

puts feed.items[0].url
# => "http://openfootball.github.io/2015/08/30/league-quick-starter.html"

puts feed.items[0].updated
# => Sun, 30 Aug 2015 00:00:00 +0000

puts feed.items[0].content
# => "Added a new quick starter sample using the Mauritius Premier League to get you started..."
...

### Reference

feedparser library - Read Web Feeds in XML, HTML, JSON, TXT and More; Build Your Own News Reader from Scratch in Twenty Lines
https://planetruby.github.io/advent2017/08-feedparser

feedparser/feedparser: feedparser gem - (universal) web feed parser and normalizer (XML w/ Atom or RSS, JSON Feed, HTML w/ Microformats e.g. h-entry/h-feed or Feed.HTML, Feed.TXT w/ YAML, JSON or INI & Markdown, etc.)
https://github.com/feedparser/feedparser
打赏

Leave a Reply

Your email address will not be published. Required fields are marked *