Search code examples
pythonmatplotlibyahoo-finance

Python Matplotlib Finance: Get the quarterly EPS of a stock


I am using Matplotlib Finance with Python to obtain stock quotes from Yahoo! Finance.

I am wondering if there is a way to obtain the EPS (earnings per share) for the current quarter as well as for the quarters of the past 5 years (i.e past 20 quarters) using Matplotlib Finance.

If not, can anyone direct me to a library for python which has this data?


Solution

  • This works for me.

    from urllib import urlopen
    from bs4 import BeautifulSoup
    
    url = 'http://www.marketwatch.com/investing/stock/goog/financials'
    text_soup = BeautifulSoup(urlopen(url).read()) #read in
    
    titles = text_soup.findAll('td', {'class': 'rowTitle'})
    for title in titles:
        if 'EPS (Basic)' in title.text:
            print [td.text for td in title.findNextSiblings(attrs={'class': 'valueCell'}) if td.text]
    

    Result: [u'15.10', u'16.42', u'18.29', u'20.27', u'23.88'] [u'-', u'8.75%', u'11.38%', u'10.85%', u'17.78%']