This script provides a way to automate sending direct messages on Instagram.
Support for chrome profiles with automatic logging in.
To use this script, you need to have the following Python packages installed:
undetected_chromedriver
selenium
requests
pyotp
You can install them using the following command:
pip3 install selenium pyotp undetected_chromedriver requests
from instagram_web import User
Basic Example (with Chrome profile and credentials):
user = User(
profile_name="myprofile",
username="my_instagram_username",
password="my_instagram_password"
)
Using Two-Factor Authentication (2FA):
user = User(
username="my_instagram_username",
password="my_instagram_password",
token="my_totp_token"
)
Running in Headless Mode:
user = User(
username="my_instagram_username",
password="my_instagram_password",
headless=True
)
Using a non auth Proxy:
user = User(
username="my_instagram_username",
password="my_instagram_password",
proxy="http://proxyserver:port"
)
Custom Chrome and ChromeDriver Paths:
user = User(
browser_executable_path="/path/to/chrome",
driver_executable_path="/path/to/chromedriver"
)
user.send_msg(to_username="recipient_username", msg="Your message here", skip_if_already_messaged=False)
Send a direct message to another user knowing msg_id:
user.send_msg_to_msg_id(msg_id="recipient_msg_id", msg="Your message here",skip_if_already_messaged=False)
cookies = user.get_cookies(close_after=False)
user.exit_driver()
If you have any questions or feedback feel free to contact me.
Caution
This script is provided for educational purposes only. Automating actions on Instagram may violate their terms of service, and your account may be subject to restrictions or bans. Use this script at your own risk.