【问题标题】:get instagram followers list with python使用 python 获取 Instagram 关注者列表
【发布时间】:2019-03-20 15:12:30
【问题描述】:

我编写的这段代码每 10 分钟给我 1000 个关注者,这是获得 1800 万关注者列表的缓慢过程。我想在更短的时间内访问 prada 的关注者列表。感谢您的回复,缓慢的过程是 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())

【问题讨论】:

  • I/O 操作很慢。如果您需要速度,请尽可能缩短它。此外,您要为每次迭代打开和关闭文件,这非常低效。
  • 感谢您的回复,但我的问题是 Instagram 限制本身。每次我因为太多查询而收到错误 429。

标签: python python-3.x


【解决方案1】:

主要瓶颈可能是从 instagram 中提取数据,但您可以通过在循环外仅打开和关闭一次来提高速度;你也不需要数组:

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

file.close()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-23
    • 1970-01-01
    • 1970-01-01
    • 2018-01-20
    • 1970-01-01
    • 2019-07-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多