Using yfinance
Try the module yfinance
(an API facade, client library to Yahoo! Finance). Some research here on SO shows how:
Then adjust to your case and play around:
import yfinance as yf
stock = yf.Ticker('APPL')
print(stock.info)
Prints the retrieved JSON data stock.info
as a dict:
{'symbol': 'APPL', 'quoteType': 'MUTUALFUND', 'exchange': 'YHD', 'exchangeTimezoneName': 'America/New_York', 'exchangeTimezoneShortName': 'EST', 'gmtOffSetMilliseconds': '-18000000', 'market': 'us_market', 'isEsgPopulated': False, 'quoteSourceName': 'Delayed Quote', 'regularMarketOpen': None, 'averageDailyVolume3Month': None, 'regularMarketTime': 1561759658, 'volume24Hr': None, 'regularMarketDayHigh': None, 'shortName': None, 'averageDailyVolume10Day': None, 'longName': None, 'regularMarketChange': None, 'regularMarketPreviousClose': None, 'preMarketPrice': None, 'exchangeDataDelayedBy': 0, 'toCurrency': None, 'postMarketChange': None, 'postMarketPrice': None, 'exchangeName': 'YHD', 'preMarketChange': None, 'circulatingSupply': None, 'regularMarketDayLow': None, 'priceHint': 2, 'regularMarketPrice': None, 'regularMarketVolume': None, 'lastMarket': None, 'regularMarketSource': 'DELAYED', 'openInterest': None, 'marketState': 'POST', 'underlyingSymbol': None, 'marketCap': None, 'volumeAllCurrencies': None, 'strikePrice': None, 'maxAge': 1, 'fromCurrency': None, 'logo_url': ''}
However, there is no institution
or any other count resembling your information-demand (given number 5,102
) like on the screenshot from Yahoo! Finance page of AAPL:

Research on the desired figure
I searched the web for Number of Institutions Holding Shares
and yfinance
and found an article explaining it:
Ticker.major_holders
and Ticker.institutional_holders
can be used to get details of shareholding of the company.
major_holders
: shows how much of the shares and float are held by the insiders and institutions
Ticker.institutional_holders
provides the details of major institutioal shareholding.
Retrieve information about holders using yfinance
import yfinance as yf
appl = yf.Ticker('APPL')
full_name = appl.info['longName']
major_holders = appl.major_holders
institutional_holders = appl.institutional_holders
print(f"Name:\n{full_name}")
print(f"Major holders:\n{major_holders}")
print(f"Institutional holders:\n{institutional_holders}")
Prints what is expected to hold the desired number:
Name:
None
Major holders:
0 1
0 Previous Close NaN
1 YTD Return NaN
2 Expense Ratio (net) NaN
3 Category NaN
4 Last Cap Gain NaN
5 Morningstar Rating NaN
6 Morningstar Risk Rating NaN
7 Sustainability Rating NaN
Institutional holders:
0 1
0 Net Assets NaN
1 Beta (5Y Monthly) NaN
2 Yield NaN
3 5y Average Return NaN
4 Holdings Turnover NaN
5 Last Dividend NaN
6 Average for Category NaN
7 Inception Date NaN
Now it is left to you to figure out, why there is no data available for APPL
.
Test also the ticker symbol AMZN
and see if the example outputs from Medium article can be reproduced with figures available ️
Parsing JSON an extracting a value
Given you have this JSON:
"institutionsCount": {
"raw": 5102,
"fmt": "5.1k",
"longFmt": "5,102"
}
Then you can parse it using Pythons standard module json
:
import json
json_text = """
"institutionsCount": {
"raw": 5102,
"fmt": "5.1k",
"longFmt": "5,102"
}
"""
obj = json.loads('{'+json_text+'}') # surrounding braces needed to make it a valid JSON (object)
print(obj['institutionsCount']['longFmt'])
# 5,102