1

我想从雅虎获得比率,我得到了其中的一些,但例如 EPS 没有给我语法,除了这个值不会显示。我已经读到使用 beautifulsoup 更容​​易,但我无法使用我当前的 python 版本。谁能帮我解决这个问题?如果 EPS 有效,我可能也会找到其他方法(收盘时,或市盈率,52 周高低)

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)

提前致谢

4

0 回答 0