使用 Python 自动化 Instagram 消息

2024年8月29日 | 阅读时长18分钟

在本文中,我们将使用Python自动化Instagram消息的发送操作。首先,让我们看看什么是Instagram。

Instagram是一个专注于照片和视频分享的著名社交媒体平台。它自2010年开始运营,并引入了Instagram快拍、购物、Instagram短视频等创新功能,保持了其吸引力。Instagram是一个由Kevin Systrom和Mike Krieger于2010年创建,后来被Facebook Inc.收购的图片和视频分享社交网站。用户可以上传照片和视频,并使用话题标签和地理标签进行过滤和分组。帖子可以与公众分享,也可以只与预先批准的关注者分享。用户可以通过标签和位置浏览他人的内容,查看热门内容,点赞照片,并关注他人以将他们的内容添加到自己的个人动态中。

2015年分辨率升级到1080像素后,这一限制被取消。它还包括了消息功能,在一个帖子中分享多张照片或视频的能力,以及一个类似于Snapchat的快拍功能,允许用户在24小时内可供他人访问的时间顺序动态中发布内容。截至2019年1月,每天有5亿人使用快拍。Instagram于2012年被Facebook收购,现在拥有超过10亿用户,已深入人们的生活。

Instagram最初的特点是只允许内容以640像素的方形(1:1)宽高比呈现,这与当时iPhone的宽度相对应。

Instagram是一个个人和企业都可以使用的平台。公司可以通过创建免费的企业账户来利用照片分享应用程序推广其品牌和产品。拥有企业账户的企业可以获得免费的参与度和曝光度分析。根据Instagram的网站,超过100万营销人员使用该平台分享他们的故事并实现商业目标。此外,60%的用户报告说该应用程序帮助他们发现新产品。

现在让我们来看看代码

代码

输出

from the listed below the list of operations select any one of the operations:
1. To provide the credentials(username/password) to log in to the website.
2. To provide the list of usernames of the users to whom to send the messages.
3. To provide the list of messages that will be sent to specified users.
4. To log in to the website and navigate to the homepage of the website.
5. To type messages for all the users and send those typed messages.
6. To exit from the code execution.
1
Enter the username to login to https://www.instagram.com/
user_name_demo
Enter the password to login to https://www.instagram.com/
P@ssw0rd
To move forward with the code, enter either [y] or [n] to halt
y
from the listed below the list of operations select any one of the operations:
1. To provide the credentials(username/password) to login into the website.
2. To provide the list of usernames of the users to whom to send the messages.
3. To provide the list of messages that will be sent to specified users.
4. To log in to the website and navigate to the homepage of the website.
5. To type messages for all the users and send those typed messages.
6. To exit from the code execution.
2
Enter the number of users to whom you want to send messages to
3
Enter the username of user 1
target_user_1
Enter the username of user 2
target_user_2
Enter the username of user 3
target_user_3
To move forward with the code, enter either [y] or [n] to halt
y

from the listed below the list of operations select any one of the operations:
1. To provide the credentials(username/password) to log in to the website.
2. To provide the list of usernames of the users to whom to send the messages.
3. To provide the list of messages that will be sent to specified users.
4. To log in to the website and navigate to the homepage of the website.
5. To type messages for all the users and send those typed messages.
6. To exit from the code execution.
3
Enter the message for the user with username target_user_1
Hi, this is a message for user1.
Enter the message for the user with username target_user_2
Hope you get this message.
Enter the message for the user with username target_user_3
User3 this message for you.
To move forward with the code, enter either [y] or [n] to halt
y
from the listed below the list of operations select any one of the operations:
1. To provide the credentials(username/password) to log in to the website.
2. To provide the list of usernames of the users to whom to send the messages.
3. To provide the list of messages that will be sent to specified users.
4. To log in to the website and navigate to the homepage of the website.
5. To type messages for all the users and send those typed messages.
6. To exit from the code execution.
4
Logged In Successfully and navigated to the homepage.
To move forward with the code, enter either [y] or [n] to halt
y
from the listed below the list of operations select any one of the operations:
1. To provide the credentials(username/password) to log in to the website.
2. To provide the list of usernames of the users to whom to send the messages.
3. To provide the list of messages that will be sent to specified users.
4. To login to the website and navigate to the homepage of the website.
5. To type messages for all the users and send those typed messages.
6. To exit from the code execution.
5
[target_user_1] message sent to [Hi this is message for user1.] successfully.
[target_user_2] message sent to [Hope you get this message.] successfully.
[target_user_3] message sent to [User3 this message for you.] successfully.
Messages were sent successfully.
To move forward with the code, enter either [y] or [n] to halt
y
from the listed below the list of operations select any one of the operations:
1. To provide the credentials(username/password) to log in to the website.
2. To provide the list of usernames of the users to whom to send the messages.
3. To provide the list of messages that will be sent to specified users.
4. To log in to the website and navigate to the homepage of the website.
5. To type messages for all the users and send those typed messages.
6. To exit from the code execution.
2
Enter the number of users to whom you want to send messages to
1
Enter the username of user 1
Ronaldo. Chris
To move forward with the code, enter either [y] or [n] to halt
y
from the listed below the list of operations select any one of the operations:
1. To provide the credentials(username/password) to log in to the website.
2. To provide the list of usernames of the users to whom to send the messages.
3. To provide the list of messages that will be sent to specified users.
4. To log in to the website and navigate to the homepage of the website.
5. To type messages for all the users and send those typed messages.
6. To exit from the code execution.
3
Enter the message for the user with the username Ronaldo.Chris
Hi, I'm a big fan of your game.
To move forward with the code, enter either [y] or [n] to halt
y
from the listed below the list of operations select any one of the operations:
1. To provide the credentials(username/password) to log in to the website.
2. To provide the list of usernames of the users to whom to send the messages.
3. To provide the list of messages that will be sent to specified users.
4. To log in to the website and navigate to the homepage of the website.
5. To type messages for all the users and send those typed messages.
6. To exit from the code execution.
5
[ronaldo. cris] message sent to [Hi I'm a big fan of your game.] successfully.
Messages were sent successfully.
To move forward with the code, enter either [y] or [n] to halt
y
from the listed below the list of operations select any one of the operations:
1. To provide the credentials(username/password) to log in to the website.
2. To provide the list of usernames of the users to whom to send the messages.
3. To provide the list of messages that will be sent to specified users.
4. To log in to the website and navigate to the homepage of the website.
5. To type messages for all the users and send those typed messages.
6. To exit from the code execution.
6

说明

在上面编写的代码中,正如我们在输出中看到的那样,主函数中创建了一个上面编写的类的对象,并且这个创建的对象用于调用上面类中编写的所有不同函数,程序的顺序是这样的:用户会获得一个选项列表供选择,用户可以从列表中选择任何操作,列表中提供的操作例如提供凭据登录网站、提供用户希望发送消息的用户名列表、提供需要发送给前一步骤中提供的用户名的消息列表,在提供所有必需的输入后,用户可以选择登录功能并导航到主页,在成功进行身份验证和登录网站后,用户然后选择输入并发送消息的选项,此选项将调用我们类中编写的主函数,该函数将实际执行在第二步中提供的用户名的相应聊天框中输入消息的操作,并且相应的消息被输入到该用户的聊天框中,然后点击发送按钮将该消息发送给目标用户,此过程将为用户在前面步骤中提供的用户名列表中的所有用户重复执行。

自动化的优势

  • 提高可靠性:自动化显然能提高生产力。然而,自动化真正闪耀的亮点是可靠性。它是每个高效IT运营部门的基础;没有它,就会混乱、动荡和用户不满意。IT运营需要掌握两种相互对立的技能:一方面,运营经理需要高级技术能力,例如理解操作系统复杂性并评估和解决问题发展过程中的能力。另一方面,同一个人必须熟练掌握按按钮和装纸。说实话,非轮班操作涉及IT组织中最乏味、重复和容易出错的职责。然而,消除人为因素消除了大多数批处理问题。
  • 优化性能:每个公司都希望其业务像纯种马一样运行。实际上,你更有可能 overworked。尽管每年计算机技术进步都使其更快、更便宜,但对它们的需求不可避免地赶上并最终超越了公司计算机基础设施的能力。因此,许多企业努力提高其系统的性能。升级硬件或购买新机器是提高性能的两个昂贵的解决方案。也可以调整系统以提高性能,但这需要一个非常熟练的专家,而这种专家并不总是可用的。当系统针对给定工作负载进行调整时,如果工作负载发生变化,则设置不再是最佳的。
  • 降低运营成本:自动化软件是一种更智能、更有效的成本管理和降低方法。最佳的潜力是提高客户(最终用户)服务,同时逐步降低成本。这种降低成本的潜力经常被管理层忽视。大多数现代服务器的运行成本很低,总拥有成本也在下降。尽管如此,运营团队的成本可能占总成本的71%。
  • 确保高可用性:公司越来越依赖技术。如果计算机不可用,公司就会遭受损失。IT管理的关键目的之一是确保高可用性。
  • 提高生产力:当组织的技术需求增加时,生产力就成为一个更大的问题。自动化操作可以通过多种方式帮助解决这些问题。自动化程序然后准确地以精确的顺序执行命令,避免操作员错误。预测作业完成并能够对日程变化进行“假设”评估,通过消除日常任务中的许多不确定性来帮助运营。

自动化的缺点

  • 工人岗位流失:自动化最严重的缺点是它消除了人工劳动。这是因为计算机化的任务可以比人类更快、更精确地完成。例如,迪士尼乐园多年来一直在使用自动驾驶汽车来运送游客。许多人担心这将导致人类就业机会的减少。
  • 需要初始培训:几十年来,工业界一直严重依赖自动化。然而,在转向自动化之前,制造商必须考虑潜在的意外影响。其中一个影响是需要大量的财政投资来维护和服务自动化系统。这些技术也比手动技术更容易受到网络攻击,如果基础设施没有得到充分保护,公司将面临风险。
  • 可能引入新的安全隐患:当工作条件意外变化时,自动化可能会带来新的安全隐患。例如,一辆无人驾驶汽车可能被设计成可以独立驾驶,但在不太理想的条件(夜晚、能见度有限等)下,如果有人走到马路上,仍然可能导致事故。
  • 仍然需要人工干预:虽然自动化的一般优势已得到证实,但某些活动仍然需要人工交互。我们以上面提到的自动驾驶汽车为例:这些车辆可以识别大多数道路障碍物,并且可以被训练停车。然而,在某些情况下,例如驾驶经过汽车传感器不清楚的障碍物时,这些技术可能会错误地解读信息并产生不必要的结果。
  • 可能变得冗余:自动化是解决各种问题的实用方法。然而,在引入变更且自动化必须更新的情况下,这种便利性可能会过时。这些类型的修改只会增加公司的工作量,并可能花费他们宝贵的时间和资源。
  • 与定制不兼容:自动化意味着多样性和灵活性的降低。与人类不同,机器只能执行有限范围的任务,并且只能完成它们被设计要做的事情,而个人可以承担广泛的任务。自动化意味着重复执行相同的过程,这通常需要统一性。一些自动化过程与针对特定客户的一次性定制不兼容。
  • 安全问题:在当今数据驱动的环境中,企业正在利用重要数据来吸引新客户、增加销售额和提高效率。不幸的是,黑客可能会利用管理大量客户/公司数据的自动化技术。许多小公司不想冒数据盗窃的风险,尽管可以采取足够的安全保护措施来避免欺诈。

因此,在本文中,我们已经了解了如何使用 Python 自动化发送 Instagram 消息的过程。