简体   繁体   中英

trying to check if instagram page exists or not

so I have a python program that takes a list with an Instagram URL in this format:

https://www.instagram.com/ + username + "/"

and then using request_html to check if the page has the word "Follower" in it. and if it does, I know that the page exists. if it doesn't, I would know that the page doesn't exist.

now I know there are ways of doing this by checking whether the HTTP response is 200 or 404 but I realized that Instagram marks even some disabled accounts as a 200 response. some HTTP responses (of disabled/nonexistent accounts) come as 404 and some come as 200

so I didn't find that as a solution

this is the program I have created to check the Instagram URLs

def username_valid():
    print("welcome to username validity checker.")
    instagram_user = input("enter username list name: ")
        
    file = open(instagram_user, "r")
    for i in file:
        session = HTMLSession()
        r = session.get(i)
        test = r.html.search('Followers')
        if test:
            print(i + " page Alive\n")
        else:
            print(i + " page Dead\n")
    file.close()

but now there is a small problem, my script worked the first time but dint work the second time, the reason for this is that Instagram is redirecting my request to the login page

if there is a solution to this pls let me know, if the solution is to log in to Instagram thru the script pls tell me how should I go about doing that. (pls not using web selenium)

There are some useful projects and libraries written on top of instagram api such as instagram-private-api and instagram-scraper . check the documentation and examples of these projects and I'm sure you can find what you are looking for.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM