There is a code

out = re.findall('window._sharedData = (.*);</script>', list_html) json_decode = json.loads(out[0]) for e in json_decode['entry_data']['ProfilePage'][0]['user']['media']['nodes']: likes = e['likes']['count'] likes = sorted(likes, key=int) print(likes) 

The code gives an error:

 TypeError: 'int' object in not iterable 

Closed due to the fact that off-topic participants insolor , Akina , jfs , Darth , Streletz 19 Oct '17 at 13:23 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reasons:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - jfs, Darth, Streletz
  • "The question is closed, as it is customary to ask questions in Russian only on Russian in Stack Overflow . Please translate your question into Russian or use Stack Overflow in English ." - insolor, Akina
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • However, to solve a problem you need to know what is inside out - andreymal
  • as said andreymal , next time it is better to attach the data with which you work, because you can not always guess what the error was - gil9red

1 answer 1

The problem is most likely in:

 likes = e['likes']['count'] 

This is confirmed by likes = sorted(likes, key=int) , because likes will be a number, like int , not a list


It will be right:

 likes = e['likes'] 
  • There is no dictionary d (the object for which d['count'] works) in the int attempt to transfer. - jfs