I am trying to scrape sports data from a web page. I have made a LIST of DICTIONARIES and i want to access values inside it. I am getting an error "list indices must be slices or integers not str". I see no reason for this to occur

This is the first time I am running into such a problem and I cannot understand what is fundamentally wrong with what I am trying to do.

My code is as follows:

data = []   Declare empty list
   for i in range(0,31):
   CODE TO GET THE DATA I WANT FROM THE WEBPAGE......
   data.append(json.loads(response))
   data[i] = data[i]['content'] 
   data[i] -----> NO error until this part. data[i] returns the nested dictionary which contains the information that I want. 

NOW i try to access specific keys in the dictionaries which are themselves in the list (data).

playerPosition = data[i]['info']['position'] ---> LIST INDICES MUST BE INT

ALSO TRIED

for d in data:
      playerPosition = d['info']['position'] ---> LIST INDICES MUST BE INT

0 Answers