我正在嘗試寫下一個 python 腳本,它允許我從雅虎獲取一些財務報表專案。我嘗試過使用 yahoofinancials 庫,但我只能獲取一整頁資料:例如,使用以下代碼:
from yahoofinancials import YahooFinancials
yahoo_financials = YahooFinancials('AAPL')
print(yahoo_financials.get_financial_stmts('annual', 'balance'))
我會得到這個:
{
"balanceSheetHistory": {
"AAPL": [
{
"2016-09-24": {
"otherCurrentLiab": 8080000000,
"otherCurrentAssets": 8283000000,
"goodWill": 5414000000,
"shortTermInvestments": 46671000000,
"longTermInvestments": 170430000000,
"cash": 20484000000,
"netTangibleAssets": 119629000000,
"totalAssets": 321686000000,
"otherLiab": 36074000000,
"totalStockholderEquity": 128249000000,
"inventory": 2132000000,
"retainedEarnings": 96364000000,
"intangibleAssets": 3206000000,
"totalCurrentAssets": 106869000000,
"otherStockholderEquity": 634000000,
"shortLongTermDebt": 11605000000,
"propertyPlantEquipment": 27010000000,
"deferredLongTermLiab": 2930000000,
"netReceivables": 29299000000,
"otherAssets": 8757000000,
"longTermDebt": 75427000000,
"totalLiab": 193437000000,
"commonStock": 31251000000,
"accountsPayable": 59321000000,
"totalCurrentLiabilities": 79006000000
}
}
]
}
}
我想獲取每個元素,例如“現金”,并將其放入包含所有這些資料的變數或陣列中,以獲取單個數字。因此,例如,如果我要獲得“現金”,我將擁有一個變數或一個陣列/串列來獲取數字(在本例中為 20484000000,為現金)。我希望我已經說清楚了。有人知道怎么做嗎?謝謝。
uj5u.com熱心網友回復:
由于輸出是 json 格式,我們必須使用 json。
from yahoofinancials import YahooFinancials
import json
yahoo_financials = YahooFinancials('AAPL')
w = yahoo_financials.get_financial_stmts('annual', 'balance')
print(w["balanceSheetHistory"]["AAPL"][2]['2019-09-28']['totalLiab'])
更改“totalLiab”以獲取所需資料并更改“2019-09-28”,您還必須更改 [2]。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/400226.html
上一篇:元組串列的所有可能組合
