Parse a RSS feed with feedparser

In this Python snippet we use the feedparser package to parse a RSS feed from 'Medium'.

Let's get the RSS feed and parse the content.


In [1]:
import feedparser

url = 'https://medium.com/feed/tag/machine-learning'

resp = feedparser.parse(url)

We need a function to extract "urls" from the text. One of the URL will linkt to the orginal article.


In [2]:
import re

def extract_url(text):
    urls = re.findall(r'href=[\'"]?([^\'" >]+)', text)
    return urls

Now we iterate over all entries in our feed and display the title and urls which were found in the summary.


In [3]:
for r in resp['entries']:
    print(r['title'])
    urls = extract_url(r['summary'])
    if urls:
        print('-->', urls[0], '\n')


Democratização da Ciência de Dados
--> https://medium.com/inmetrics/democratizacao-da-ciencia-de-dados-43bc7f2e789d?source=rss------machine_learning-5 

Beyond the ROC AUC: Toward Defining Better Performance Metrics
--> https://medium.com/@jbohne/beyond-the-roc-auc-toward-defining-better-performance-metrics-b11f5d35adda?source=rss------machine_learning-5 

Are you Chinese, Japanese or Korean?
--> https://medium.com/@bibekchaudhary/are-you-chinese-japanese-or-korean-93e4bf270a5?source=rss------machine_learning-5 

Implementing Adam Optimizer for fast convergence in Neural Networks
--> https://medium.com/@2016csb1050/implementing-adam-optimizer-for-fast-convergence-in-neural-networks-47c35ce2c2e3?source=rss------machine_learning-5 

Preventing Machine Learning Bias
--> https://medium.com/@sajin.stanislav/preventing-machine-learning-bias-d01adfe9f1fa?source=rss------machine_learning-5 

Dengue Fever and How to Predict It
--> https://medium.com/@bconn992/dengue-fever-and-how-to-predict-it-a32eab1dbb18?source=rss------machine_learning-5 

Waiver-Wire-a-Week-Ahead Advice for Fantasy Football Week 9 based on Machine Learning
--> https://medium.com/fantasy-outliers/waiver-wire-a-week-ahead-advice-for-fantasy-football-week-9-based-on-machine-learning-d25f05af3464?source=rss------machine_learning-5 

Word Embedding Comparison for Disease Named Entity Recognition
--> https://medium.com/@aus10_powers/word-embedding-comparison-for-disease-named-entity-recognition-a99850653e1c?source=rss------machine_learning-5 

LEARN AI IN ONE WEEK!!!
--> https://medium.com/@JeffXu999/learn-ai-in-one-week-2a0e8e65eac8?source=rss------machine_learning-5 

Exploratoryデスクトップ v5.0をリリースしました!
--> https://blog.exploratory.io/exploratory%E3%83%87%E3%82%B9%E3%82%AF%E3%83%88%E3%83%83%E3%83%97-v5-0%E3%82%92%E3%83%AA%E3%83%AA%E3%83%BC%E3%82%B9%E3%81%97%E3%81%BE%E3%81%97%E3%81%9F-39ef9ea61b8b?source=rss------machine_learning-5 


In [ ]: