[英]how to pull certain data from a list response from instagrapi
so I'm working on some code to pull the pictures of people who have liked a post on instagram.所以我正在编写一些代码来提取在 Instagram 上喜欢帖子的人的照片。 i'm using instagrapi for the api system, but when using
api.media_likers
which returns a list of needed info.我将 instagrapi 用于 api 系统,但是当使用
api.media_likers
返回所需信息的列表时。 for some reason it returns it with TypeError: 'UserShort' object is not subscriptable
.由于某种原因,它返回
TypeError: 'UserShort' object is not subscriptable
。 Im not sure what to do because the code here:我不确定该怎么做,因为这里的代码:
from instagrapi import Client
insta_user = ""
insta_pass = ""
api = Client() #logs in
api.login(insta_user, insta_pass) #logs in
url = input("Please enter the url to the populer photo: ")
populer_photo_id = api.media_pk_from_url(url) # gets media id from url given from user
print(f"got media id ==> {populer_photo_id}")
get_likes = api.media_info(populer_photo_id).dict() # gets number of likes
likes = get_likes['like_count'] # gets number of likes
likers_res = api.media_likers(populer_photo_id) # gets the people who have liked said post (returns in list)
print(list((object['username'] for object in likers_res)))
This is supposed to return the username from the list but instead returns这应该从列表中返回用户名,而是返回
Please enter the url to the populer photo: https://www.instagram.com/p/xxxxxxxxxx/
got media id ==> xxxxxxxxxxxxxxxx
Traceback (most recent call last):
File "c:\Users\gagem\Documents\Pr0j3cts\insta-promo\testing-api-file.py", line 43, in <module>
print(list((object['username'] for object in likers_res)))
File "c:\Users\gagem\Documents\Pr0j3cts\insta-promo\testing-api-file.py", line 43, in <genexpr>
print(list((object['username'] for object in likers_res)))
TypeError: 'UserShort' object is not subscriptable
you just need to change你只需要改变
print(list((object['username'] for object in likers_res)))
into进入
print(list((object.username for object in likers_res)))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.