Reputation: 1921
I would like to use either the python request module or the urllib module to get the company name by passing the stock symbol to the Yahoo Finance API. I don't want to use the YFinance Module because I don't need Panda's, Numpy, etc. I am trying to keep the size of my program down.
Here is the endpoint from the YFinance wrapper module:
name = yf.Ticker(symbol).info['shortName']
I'm just not sure how to make the request without the module.
Upvotes: 1
Views: 5553
Reputation: 11
import yfinance as yf
ticker = "AAPL"
stock_name = yf.Ticker(ticker).info["longName"]
print(stock_name)
Upvotes: 0
Reputation: 1921
Using the endpoint from @r-beginners comment, I created a simple function using the urllib
module to retrieve the company name from Yahoo Finance in Python. No YFinance
module is needed. I hope this is helpful to someone else.
def get_yahoo_shortname(symbol):
response = urllib.request.urlopen(f'https://query2.finance.yahoo.com/v1/finance/search?q={symbol}')
content = response.read()
data = json.loads(content.decode('utf8'))['quotes'][0]['shortname']
return data
Upvotes: 2