1

I want to get ratios from Yahoo and I got some of them, but for example EPS does not give me a syntax, besides that the value just won't show up. I read already that using beautifulsoup is easier but I cannot get that one working with my current python version. Can anyone help me out with this one? If EPS works I probably find out how to do others as well (At close, or PE ratio, 52week high low)

import urllib.request
import re

tickerlist = input("Enter ticker: ")

#htmlfile = urllib.request.urlopen("http://finance.yahoo.com/q?s=GOOG")
htmlfile = urllib.request.urlopen("https://finance.yahoo.com/quote/" + 
tickerlist + "?p=" + tickerlist)

htmltext = htmlfile.read()

pattern = re.compile('\"regularMarketPrice\":{\"raw\":(.*?),')
regularMarketPrice = pattern.findall(str(htmltext))
print('regularMarketPrice:', regularMarketPrice[0])

# EPS Ratio
pattern = re.compile('<span>EPS(.*?)</span>')
eps_ratio = pattern.findall(str(htmltext))
print('EPS Ratio:',eps_ratio)

Thanks in advance

0 Answers0