使用 python 脚本获取 Instagram 粉丝列表

Gab*_*ita 7 python python-3.x instagram

我是 Python 编程的初学者,我想将我的 Instagram 粉丝和关注列表导出到一个 excel 文件中。在谷歌上搜索我找到了这篇文章。我将粘贴以下代码:

# 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())
Run Code Online (Sandbox Code Playgroud)

我编辑的只是“登录或加载会话”部分中的用户名和密码以及“获取配置文件元数据”部分中的“prada”。所以我的代码看起来像这样:

# Login or load session
L.login("myusername", "mypassword")        # (login)


# Obtain profile metadata
profile = instaloader.Profile.from_username(L.context, "myusername")
Run Code Online (Sandbox Code Playgroud)

虽然我重置了密码,但仍然出现以下错误:

Traceback (most recent call last):
  File "D:/ ..... /insta_followers.py", line 6, in <module>
    L.login("myusername", "mypassword")        # (login)
  File "C:\Users\Myuser\AppData\Local\Programs\Python\Python38-32\lib\site-packages\instaloader\instaloader.py", line 483, in login
    self.context.login(user, passwd)
  File "C:\Users\Myuser\AppData\Local\Programs\Python\Python38-32\lib\site-packages\instaloader\instaloadercontext.py", line 254, in login
    raise BadCredentialsException('Login error: Wrong password.')
instaloader.exceptions.BadCredentialsException: Login error: Wrong password.
Run Code Online (Sandbox Code Playgroud)

我 100% 密码有效,因为我在浏览器中测试过。我的密码包含大小写字母、数字和符号。由于密码中的一个字符,可能会出现此错误?或者也许是因为我最近重置了密码?你能给我一些建议吗?

我正在使用 PyCharm 社区 2020.2 和 Python 3.8。

谢谢

我的最终代码如下所示:

# Get instance
import instaloader

L = instaloader.Instaloader()

# Login or load session
username = "myusername"
password = "mypassword"
L.login(username, password)  # (login)

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

# 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())
Run Code Online (Sandbox Code Playgroud)

nih*_*lok 1

我用我自己的 Instagram 帐户准确复制了您的代码,并且它有效。检查您的密码是否作为原始字符串输入,看看是否有任何效果。

password = r'********'
Run Code Online (Sandbox Code Playgroud)

稍微泄露您的新密码的一些细节,哈哈,可能是您其中有一两个反斜杠,需要忽略!