用python脚本获取Instagram关注者列表

krcsximq  于 2022-11-19  发布在  Python
关注(0)|答案(1)|浏览(198)

我是Python编程的初学者,我想将我的Instagram关注者和以下列表导出到一个Excel文件中。在谷歌上搜索,我发现了这个post。我将粘贴下面的代码:

# 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())

我所编辑的只是“Login or load session”部分的用户名和密码以及“Obtain profile metadata”部分的“prada”。所以我的代码看起来像这样:

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

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

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

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.

我的密码是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())
ljo96ir5

ljo96ir51#

我用我自己的Instagram账户完全复制了你的代码,它工作正常。检查你的密码是否作为原始字符串输入,看看是否有任何效果。

password = r'********'

泄露一些细节,你的新密码稍微笑,它可能是你有一个反斜杠或两个在那里,这需要被忽略!

相关问题