Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Instagram followers list with python script

I'm beginner in python programming and i want to export my Instagram followers and following list into an excel file. Searching on Google i found this post. I will paste the code bellow:

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

All i edited was the username and the password from "Login or load session" section and "prada" from "Obtain profile metadata" section. So my code is looking like this:

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


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

Although I reset the password I still get the following error:

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.

I'm 100% the password is working because i tested in browser. My password contains uppercase and lowercase letters, numbers and signs. It is possible to get this error because one of the characters from the password? Or maybe because i recently reset the password? Can you give me some advice please?

I'm using PyCharm Community 2020.2 and Python 3.8.

Thank you

L.E.

My final code is looking like this:

# 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())
like image 416
Gabriel Ghita Avatar asked Oct 26 '20 15:10

Gabriel Ghita


People also ask

How do I extract a list of followers on Instagram?

Sign in instagram and open the extension. 2. Select or input the IG user you want to export, choose the export type then click 'GO'.

How do you scrape Instagram followers in Python?

Open a terminal or cmd again and run the bot using this command: python run.py . Enter the username of the person whose followers you want to scrape. Enter how many followers you want to scrape. And that's it.


Video Answer


1 Answers

I copied your code exactly with my own Instagram account and it works. Check your password is being input as a raw string and see if that has any effect.

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

Divulging some details of your new password slightly lol, it could be that you have a backslash or two in there, which need to be ignored!

like image 127
nihilok Avatar answered Oct 19 '22 06:10

nihilok