使用Python在 Instagram 上自动发布图片
先决条件: Python编程语言
Instagram 是 Facebook 旗下的照片和视频共享社交网络服务, Python提供了与 Instagram 交互的强大工具。在本文中,我们将了解如何仅通过编写几行Python代码就可以在 Instagram 帐户上自动发布图片。
第1步:
在终端中使用以下命令安装“ instabot ”包。
pip install instabot
第2步:
从“ instabot ”包导入类“ Bot ”。
Python3
from instabot import Bot
Python3
bot = Bot()
Python3
bot.login(username = "******",
password = "ppppppp")
Python3
bot.upload_photo("provide the path to the picture here",
caption = "provide the caption that you \
want to display on the post here")
Python3
from instabot import Bot
bot = Bot()
bot.login(username = "user_name",
password = "user_password")
# Recommended to put the photo
# you want to upload in the same
# directory where this Python code
# is located else you will have
# to provide full path for the photo
bot.upload_photo("Technical-Scripter-2019.jpg",
caption ="Technical Scripter Event 2019")
第 3 步:
创建一个变量让我们说'bot'并将类'Bot'存储在其中。
Python3
bot = Bot()
第4步:
使用以下命令登录您的 Instagram 帐户。提供您的 Instagram“用户名”和“密码”。
Python3
bot.login(username = "******",
password = "ppppppp")
第 5 步:
使用以下命令上传您的照片。
Python3
bot.upload_photo("provide the path to the picture here",
caption = "provide the caption that you \
want to display on the post here")
以下是在 Instagram 上上传照片的完整程序。下面的程序上传了一张“Technical Scripter 2019”的图片。
Python3
from instabot import Bot
bot = Bot()
bot.login(username = "user_name",
password = "user_password")
# Recommended to put the photo
# you want to upload in the same
# directory where this Python code
# is located else you will have
# to provide full path for the photo
bot.upload_photo("Technical-Scripter-2019.jpg",
caption ="Technical Scripter Event 2019")
以下是上述照片在 Instagram 上发布的屏幕截图。