看看Instagram是否存在帐户的最佳API?

时间:2018-11-19 02:14:14

标签: instagram

我有一个用户名列表,此列表中,我想查看以编程方式存在具有该用户名的Instagram帐户。

什么是用来输入用户名列表并解析帐户是否存在的最佳工具(或API)?

谢谢

3 个答案:

答案 0 :(得分:2)

您要使用哪种语言?

有些东西可以在Python 3中使用:

import requests

username = "whatever"
response = requests.get("https://instagram.com/" + username + "/")
if response.status_code == 404 :
    #the username isn't taken

或者,如果您要严格查找列表,可以执行以下操作:

import requests

notTaken = []
list = ["username1", "username2", "username3", "etc..."]
for i in list :
    response = requests.get("https://instagram.com/" + i + "/")
        if response.status_code == 404 :
            notTaken.append(i)

然后,notTaken将是arent用户名的列表,您可以使用它进行任何操作,例如:

print(notTaken)

for i in notTaken :
    print(i)

如果列表在文件中,并且它们各自位于单独的行上,则可以执行此操作,如果它们使用分隔符,则只需更改分隔符变量,使其等于分隔符即可。

import requests
filePath = "./list.txt"
separator = "\n" #this means newline, but you could use "," or ";" or whatever
list = open(filePath, "r").read().split(seperator)
notTaken = []
for i in list :
    response = requests.get("https://instagram.com/" + i + "/")
        if response.status_code == 404 :
            notTaken.append(i)

答案 1 :(得分:1)

据我所知,没有任何api可以做到。但是您可以编写程序请求来检查https://www.instagram.com/ +用户名+ /。这可能有助于您检查该用户的存在与否,并获取有关帖子数,关注者和关注者的信息。祝好运!

答案 2 :(得分:0)

在Shell中,我使用以下命令来查看用户是否存在:

curl -L -s https://www.instagram.com/username.here/ | grep -c "the page may have been removed"

找到在Python脚本中使用此Shell命令的方法,我相信有os.system('Shell command here')这样的方法可以在Python脚本中使用bash命令,但似乎已弃用。

相关问题