I'm trying to retrieve Sector and Industry data for a list of stocks from Yahoo Finance
My code worked the first time I ran it, but now I get a long response that ends in "TypeError: string indices must be integers"
I've seen several posts that recommend using an override for pandas datareader to fix this a similar "string indices must be integers" but I'm not using pandas datareader as I'm looking to retrieve sector and industry from the profile of each ticker.
My code looks like this
import yfinance as yf
companies = ['AAPL','AMZN','GOOG','META','NFLX','TSLA']
i=0
while i<len(companies):
stock=yf.Ticker(companies[i])
print(stock.info['sector'])
print(stock.info['industry'])
Response is as follows:
Traceback (most recent call last):
File "C:/Python_Programs/stack_overflow_code.py", line 8, in <module>
print(stock.info['sector'])
File "C:\PerfLogs\Python Software\Python 3_10_7\lib\site-packages\yfinance\ticker.py", line 138, in info
return self.get_info()
File "C:\PerfLogs\Python Software\Python 3_10_7\lib\site-packages\yfinance\base.py", line 894, in get_info
data = self._quote.info
File "C:\PerfLogs\Python Software\Python 3_10_7\lib\site-packages\yfinance\scrapers\quote.py", line 27, in info
self._scrape(self.proxy)
File "C:\PerfLogs\Python Software\Python 3_10_7\lib\site-packages\yfinance\scrapers\quote.py", line 58, in _scrape
quote_summary_store = json_data['QuoteSummaryStore']
TypeError: string indices must be integers