用python获取instagram关注者列表

2024-04-19 12:06:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我写的这段代码每10分钟给我1000个关注者,这对于获得1800万个关注者列表来说是一个缓慢的过程。我想访问普拉达的追随者名单在较短的数量时间到了。谢谢对于您的回复,这个缓慢的过程是instagram限制错误。所以给一个方法来更快地得到追随者列表。在

 # Get instance
import instaloader
L = instaloader.Instaloader()

# Login or load session
L.login(username, password)        # (login)


# Obtain profile metadata
profile = instaloader.Profile.from_username(L.context, "prada")

# Print list of followees



follow_list = []
count=0
for followee in profile.get_followers():
    follow_list.append(followee.username)
    file = open("prada_followers.txt","a+")
    file.write(follow_list[count])
    file.write("\n")
    file.close()
    print(follow_list[count])
    count=count+1
# (likewise with profile.get_followers())

Tags: 列表get过程countusernameloginprofilelist
1条回答
网友
1楼 · 发布于 2024-04-19 12:06:06

主要瓶颈可能是从instagram中提取数据,但您可以通过在循环之外只打开和关闭一次来提高速度;而且您不需要阵列:

file = open("prada_followers.txt","a+")
for followee in profile.get_followers():
    username = followee.username
    file.write(username + "\n")
    print(username)

file.close()

相关问题 更多 >