引言

在社交媒体时代,Instagram 成为了许多人展示自我、建立社交网络的重要平台。然而,许多用户在使用 Instagram 时会遇到一个令人头疼的问题:如何知道哪些人你关注了,但他们却没有关注你?手动检查关注列表和粉丝列表不仅耗时,还容易遗漏。这种情况下,一个能够自动分析 Instagram 关注关系的工具显得尤为重要。

main.py

代码解析说明

main.pyinstaloader
# Made by Maxim Iliouchenko (https://github.com/maxily1)

# Importing Libraries
import instaloader
import argparse

# Get instance
L = instaloader.Instaloader()

# Creating an argument parser
parser = argparse.ArgumentParser(description='Process log-in data')

# Adding arguments
parser.add_argument('-u', type=str, required=True, help="Enter a username which will be used in the app.")
parser.add_argument('-p', type=str, required=True, help="Enter a password which will be used in the app.")

# Parsing the args
args = parser.parse_args()

# Defining the args into variables
user_name = args.u
pass_word = args.p

# Login data and load session
L.login(user_name, pass_word)

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

# Making a list with the usernames of the followers
followers_list = []
for follower in profile.get_followers():
    username = follower.username
    followers_list.append(username)

# Making a list with all of the people who you're following
following_list = []
for following in profile.get_followees():
    username = following.username
    following_list.append(username)

# Find people who don't follow back
not_following_back = []
for following in following_list:
    if following not in followers_list:
        not_following_back.append(following)

print(not_following_back)

choice = input("Would you like to save the people who don't follow you as a file? (y/n): ")
if choice == "y":
    f = open("dont_follow_back.txt", "w")
    for person in not_following_back:
        f.write(person + "\n")
else:
    exit

代码解析

import instaloaderinstaloaderimport argparseargparseL = instaloader.Instaloader()instaloaderparser = argparse.ArgumentParser(description='Process log-in data')parser.add_argument('-u', type=str, required=True, help="Enter a username which will be used in the app.")parser.add_argument('-p', type=str, required=True, help="Enter a password which will be used in the app.")args = parser.parse_args()L.login(user_name, pass_word)profile = instaloader.Profile.from_username(L.context, username=user_name)followers_listprofile.get_followers()following_listprofile.get_followees()not_following_backdont_follow_back.txt

可扩展或可演变的实际应用场景

1. 社交媒体营销分析

对于品牌或营销人员来说,了解哪些用户没有关注回可以帮助优化营销策略。例如,可以定期运行此脚本,分析关注者的变化趋势,从而决定是否需要调整互动策略或取消关注某些用户。

2. 个人账号管理

对于个人用户,此脚本可以帮助清理关注列表,删除那些不互动的用户。此外,还可以扩展功能,分析互动率、评论和点赞情况,以更好地管理个人账号。

总结

main.pyinstaloader

源码获取

完整代码已开源,包含详细的注释文档:
🔗 [GitCode仓库] https://gitcode.com/laonong-1024/python-automation-scripts
📥 [备用下载] https://pan.quark.cn/s/654cf649e5a6 提取码:f5VG