我在一个名为stocktickers.csv的文件中有一个tickers列表(如下所示):
我想从该列表中提取雅虎金融资产负债表数据,并将其输入stocktickers.csv文件,如下所示。“有形账面价值”和“共享已发行”是在每个股票发行人的资产负债表网页上找到的字段,如AMD的:https://finance.yahoo.com/quote/AMD/balance-sheet?p=AMD
这就是我到目前为止所拥有的,多年来它一直在刮平有形的账面价值
from bs4 import BeautifulSoup
import requests
header = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36'
}
url = 'https://finance.yahoo.com/quote/AAPL/balance-sheet?p=AAPL'
response = requests.get(url, headers=header)
html = response.text
soup = BeautifulSoup(html, "html.parser")
main = soup.find("div", {"data-reactid": "195"}) #or 196
divs = main.find_all("div")
for div in divs:
span = div.find("span")
try:
print(span.text)
except:
pass
结果:
Tangible Book Value
Tangible Book Value
65,339,000
90,488,000
107,147,000
126,032,000
如果有一种方法可以使用get_balance_sheet()
(从yfinance module)来刮取特定的资产负债表字段,比如上面的字段,那也太好了
尝试financialmodelingprep API。您可以很容易地从JSON请求中获取该信息,因此不必刮取它
相关问题 更多 >
编程相关推荐