In [1]:
import json
To parse rss feed, we will use feedparser package.
Let us import the package first.
In [2]:
import feedparser
In [3]:
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0'
}
Let us try to read the rss feed for the stock 'snow'
In [4]:
ticker = 'snow'
In [5]:
rssfeedurl = 'https://feeds.finance.yahoo.com/rss/2.0/headline?s=%s®ion=US&lang=en-US'%ticker
In [6]:
NewsFeed = feedparser.parse(rssfeedurl)
NewsFeed is like a Python dictionary, we can use keys and indices to access it.
In [7]:
type(NewsFeed)
Out[7]:
In [8]:
NewsFeed.keys()
Out[8]:
Let us check how many entries we have.
In [9]:
len(NewsFeed.entries)
Out[9]:
Let us check our first news item.
In [10]:
NewsFeed.entries[0]
Out[10]:
We can access any item from this news item using keyname.
In [11]:
NewsFeed.entries[0].summary
Out[11]:
Related Notebooks
- How To Analyze Yahoo Finance Data With R
- Calculate Stock Options Max Pain Using Data From Yahoo Finance With Python
- Pandas Datareader To Download Stocks Data From Google And Yahoo Finance
- How To Install Python With Conda
- How To Get Measures Of Spread With Python
- How to Sort Pandas DataFrame with Examples
- How To Append Rows With Concat to a Pandas DataFrame
- JSON Parse Error Syntax Error Unexpected token N In JSON
- How To Replace na Values with Zeros In R Dataframe