Selenium And Python Bot For Instagram Login

Find the data you need here

We provide programming data of 20 most popular languages, hope to help you!

Previous PostNext Post

Selenium and python instagram code example

Example: python instagram bot from instapy import InstaPy session = InstaPy(username="<your_username>", password="<your_password>") session.login() session.like_by_t Menu NEWBEDEV Python Javascript Linux Cheat sheet

from instapy import InstaPy

session = InstaPy(username="<your_username>", password="<your_password>")
session.login()
session.like_by_tags(["bmw", "mercedes"], amount=5)
session.set_dont_like(["naked", "nsfw"])
session.set_do_follow(True, percentage=50)
session.set_do_comment(True, percentage=50)
session.set_comments(["Nice!", "Sweet!", "Beautiful :heart_eyes:"])
session.end()

Selenium python for creating a instagram login liker bot

I am using selenium for python to create a simple liker bot for instagram. The idea is to like the first photo of a tag (in this example is "sunset"). It correctly selects the first photo but does not insert a like. The code is as follows: from selenium import webdriver from selenium.webdriver.chrome.options import Options from time import

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

from time import sleep

import User_data

chrome_options=Options()

chrome_options.add_argument('--lang=en')
browser = webdriver.Chrome(chrome_options=chrome_options)

browser.get("https://www.instagram.com/accounts/login/")
sleep(1)

browser.find_element_by_name("username").send_keys(User_data.username)
browser.find_element_by_name("password").send_keys(User_data.password)

sleep(1)

browser.find_element_by_xpath('//*[@id="react-root"]/section/main/div/article/div/div[1]/div/form/div[3]/button').click()

sleep(1)
browser.get("https://www.instagram.com/explore/tags/sunset/")

sleep(1)
browser.find_element_by_xpath("//article/div[2]/div/div/div/a/div/div[2]").click()
sleep(1)
browser.find_element_by_xpath("//button/span[contains(@class. 'glyphsSpriteHeart__outline__24__grey_9 u-__7') ]").click()
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

from time import sleep

import User_data

chrome_options=Options()

chrome_options.add_argument('--lang=en')
browser = webdriver.Chrome(chrome_options=chrome_options)

browser.get("https://www.instagram.com/accounts/login/")
sleep(1)

browser.find_element_by_name("username").send_keys(User_data.username)
browser.find_element_by_name("password").send_keys(User_data.password)

sleep(2)

buttons = browser.find_elements_by_tag_name('button')
for button_element in buttons:
    print(button_element.text)     #- This will print the text of the buttons present
Show
Log in
Log in with Facebook
buttons[1].click()

Building an Instagram Bot with Python and Selenium to Gain More Followers

You’ll also need to fill Instagram info under “instagram” so the bot can login into your account. execute the following code 200 times (first …

{  "db": {    "host": "localhost",    "user": "root",    "pass": "",    "database": "instabot"  },  "instagram": {    "user": "",    "pass": ""  },  "config": {    "days_to_unfollow": 1,    "likes_over": 150,    "check_followers_every": 3600,    "hashtags": []  }}
import jsonINST_USER= INST_PASS= USER= PASS= HOST= DATABASE= POST_COMMENTS= ''LIKES_LIMIT= DAYS_TO_UNFOLLOW= CHECK_FOLLOWERS_EVERY= 0HASHTAGS= []def init():    global INST_USER, INST_PASS, USER, PASS, HOST, DATABASE, LIKES_LIMIT, DAYS_TO_UNFOLLOW, CHECK_FOLLOWERS_EVERY, HASHTAGS    # read file    data = None    with open('settings.json', 'r') as myfile:        data = myfile.read()    obj = json.loads(data)    INST_USER = obj['instagram']['user']    INST_PASS = obj['instagram']['pass']    USER = obj['db']['user']    HOST = obj['db']['host']    PASS = obj['db']['pass']    DATABASE = obj['db']['database']    LIKES_LIMIT = obj['config']['likes_over']    CHECK_FOLLOWERS_EVERY = obj['config']['check_followers_every']    HASHTAGS = obj['config']['hashtags']    DAYS_TO_UNFOLLOW = obj['config']['days_to_unfollow']
import Constantsdef init(webdriver):    returndef update(webdriver):    return
from selenium import webdriverimport BotEnginechromedriver_path = 'YOUR CHROMEDRIVER PATH' webdriver = webdriver.Chrome(executable_path=chromedriver_path)BotEngine.init(webdriver)BotEngine.update(webdriver)webdriver.close()
import datetimedef days_since_date(n):    diff = datetime.datetime.now().date() - n    return diff.days
import mysql.connectorimport Constantsclass DBHandler:    def __init__(self):        DBHandler.HOST = Constants.HOST        DBHandler.USER = Constants.USER        DBHandler.DBNAME = Constants.DATABASE        DBHandler.PASSWORD = Constants.PASS    HOST = Constants.HOST    USER = Constants.USER    DBNAME = Constants.DATABASE    PASSWORD = Constants.PASS    @staticmethod    def get_mydb():        if DBHandler.DBNAME == '':            Constants.init()        db = DBHandler()        mydb = db.connect()        return mydb    def connect(self):        mydb = mysql.connector.connect(            host=DBHandler.HOST,            user=DBHandler.USER,            passwd=DBHandler.PASSWORD,            database = DBHandler.DBNAME        )        return mydb
import datetime, TimeHelperfrom DBHandler import *import Constants#delete user by usernamedef delete_user(username):    mydb = DBHandler.get_mydb()    cursor = mydb.cursor()    sql = "DELETE FROM followed_users WHERE username = '{0}'".format(username)    cursor.execute(sql)    mydb.commit()#add new usernamedef add_user(username):    mydb = DBHandler.get_mydb()    cursor = mydb.cursor()    now = datetime.datetime.now().date()    cursor.execute("INSERT INTO followed_users(username, date_added) VALUES(%s,%s)",(username, now))    mydb.commit()#check if any user qualifies to be unfolloweddef check_unfollow_list():    mydb = DBHandler.get_mydb()    cursor = mydb.cursor()    cursor.execute("SELECT * FROM followed_users")    results = cursor.fetchall()    users_to_unfollow = []    for r in results:        d = TimeHelper.days_since_date(r[1])        if d > Constants.DAYS_TO_UNFOLLOW:            users_to_unfollow.append(r[0])    return users_to_unfollow#get all followed usersdef get_followed_users():    users = []    mydb = DBHandler.get_mydb()    cursor = mydb.cursor()    cursor.execute("SELECT * FROM followed_users")    results = cursor.fetchall()    for r in results:        users.append(r[0])    return users
import AccountAgent, DBUsersimport Constantsimport datetimedef init(webdriver):    Constants.init()    AccountAgent.login(webdriver)def update(webdriver):    return

Python Automation With Selenium: Part 1

pip install virtualenv
mv ~Downloads/chromedriver /usr/local/bin
mkdir <projectName>cd <projectName>virtualenv -p python3 <venvName>
source <venvName>/bin/activate
pip install selenium
from selenium import webdriverfrom time import sleepfrom selenium.webdriver.common.keys import Keysfrom random import randint
class Bot():     def __init__(self):        self.login('benscstutorials')       def login(self, username):        print('hi')def main():    my_bot = Bot()if __name__ == '__main__':    main()
self.driver = webdriver.Chrome()
self.driver.get('https://www.instagram.com/')
sleep(5)
username_input = self.driver.find_element_by_xpath("//input[@name='username']")username_input.send_keys(username)password_input = self.driver.find_element_by_xpath("//input[@name='password']")password_input.send_keys(pw)
pw = 'XXXXXX'
from secrets import pw
submit_btn = self.driver.find_element_by_xpath(“//button[@type=’submit’]”)submit_btn.click()
sleep(5)not_now_btn = self.driver.find_element_by_xpath(‘/html/body/div[4]/div/div/div[3]/button[2]’)not_now_btn.click()
from selenium import webdriverfrom time import sleepfrom secrets import pwfrom selenium.webdriver.common.keys import Keysfrom random import randintclass Bot():    def __init__(self):        self.login('benscstutorials')        def login(self, username):        self.driver = webdriver.Chrome()           self.driver.get('https://www.instagram.com/')        sleep(5)        username_input = self.driver.find_element_by_xpath(            "//input[@name='username']")        username_input.send_keys(username)        password_input = self.driver.find_element_by_xpath(            "//input[@name='password']")        password_input.send_keys(pw)        submit_btn = self.driver.find_element_by_xpath(            "//button[@type='submit']")        submit_btn.click()        sleep(5)        not_now_btn = self.driver.find_element_by_xpath(            '/html/body/div[4]/div/div/div[3]/button[2]')        not_now_btn.click()def main():    my_bot = Bot()if __name__ == '__main__':    main()

Using Selenium in Python to enter Login Information to Instagram

Does anybody know how to automate the login to Instagram using python. I am able to login in other sites, but Instagram just won't work. Put the following code login to instagram using selenium . complete, verifiable example. Pasting the code here is preferred over linking to off-site resources such as image hosts. – GoBusto. Feb 4

element = driver.find_element_by_xpath('//input[@name='username']')
element.send_keys('my username')
frame = driver.find_element_by_css_selector("iframe.hiFrame")
driver.switch_to.frame(frame)
element = driver.find_element_by_xpath("//input[@name='username']")
driver.switch_to.default_content()
from selenium import webdriver

username = "Your Username"
password = "Your Password"

getdriver = ("https://www.instagram.com/accounts/login/")

driver = webdriver.Firefox()
driver.get(getdriver)

driver.find_element_by_xpath("//input[@name='username']").send_keys(username)
driver.find_element_by_xpath("//input[@name='password']").send_keys(password)
driver.find_element_by_xpath("//button[contains(.,'Log in')]").click()
import time

....
....

driver.get(URL)

time.sleep(3)

element = driver.find_element_by_xpath("//input[@name='username']")
element.send_keys('my username')
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
drv= webdriver.Chrome()
drv.get('https://www.instagram.com/accounts/login/?source=auth_switcher')
drv.find_element_by_name("username").send_keys('your_username_here')
drv.find_element_by_name("password").send_keys('your_password_here') 
drv.find_element_by_name("password").send_keys(u'\ue007')
element = driver.find_element_by_xpath("//input[@name='username']")
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)

username = driver.find_element_by_xpath("//input[@name='username']")
password = driver.find_element_by_name("password")

username.send_keys("YOUR USERNAME")
password.send_keys("YOUR PASSWORD")

password.send_keys(Keys.RETURN)

Let’s create an Instagram bot to show you the power of Selenium!

bot = InstagramBot('youremail', 'yourpassword') bot.signIn() Let’s open our terminal and run the following command: python main.py. A new instance of Chrome should open the Instagram login page. The inputs …

class InstagramBot():   def __init__   def signIn   def followWithUsername   def unfollowWithUsername   def getUserFollowers   def closeBrowser   def __exit__
pip install selenium
bot = InstagramBot('youremail', 'yourpassword')bot.signIn()
python main.py
bot = InstagramBot('youremail', 'yourpassword')bot.signIn()bot.followWithUsername('therock')bot.unfollowWithUsername('therock')
print(bot.getUserFollowers('therock', 50))

Previous PostNext Post

Related code examples