Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
import random
import sys
def print_same_line(text):
sys.stdout.write('\r')
sys.stdout.flush()
sys.stdout.write(text)
sys.stdout.flush()
class InstagramBot:
def __init__(self, username, password):
self.username = username
self.password = password
self.driver = webdriver.Chrome()
def closeBrowser(self):
self.driver.close()
def login(self):
driver = self.driver
driver.get("https://www.instagram.com/")
time.sleep(2)
login_button = driver.find_element_by_xpath("//a[@href='/accounts/login/?source=auth_switcher']")
login_button.click()
time.sleep(2)
user_name_elem = driver.find_element_by_xpath("//input[@name='username']")
user_name_elem.clear()
user_name_elem.send_keys(self.username)
passworword_elem = driver.find_element_by_xpath("//input[@name='password']")
passworword_elem.clear()
passworword_elem.send_keys(self.password)
passworword_elem.send_keys(Keys.RETURN)
time.sleep(2)
def like_photo(self, hashtag):
driver = self.driver
driver.get("https://www.instagram.com/explore/tags/" + hashtag + "/")
time.sleep(2)
# gathering photos
pic_hrefs = []
for i in range(1, 7):
try:
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
time.sleep(2)
# get tags
hrefs_in_view = driver.find_elements_by_tag_name('a')
# finding relevant hrefs
hrefs_in_view = [elem.get_attribute('href') for elem in hrefs_in_view
if '.com/p/' in elem.get_attribute('href')]
# building list of unique photos
[pic_hrefs.append(href) for href in hrefs_in_view if href not in pic_hrefs]
# print("Check: pic href length " + str(len(pic_hrefs)))
except Exception:
continue
# Liking photos
unique_photos = len(pic_hrefs)
for pic_href in pic_hrefs:
driver.get(pic_href)
time.sleep(2)
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
try:
time.sleep(random.randint(2, 4))
like_button = lambda: driver.find_element_by_xpath('//span[@aria-label="Like"]').click()
like_button().click()
for second in reversed(range(0, random.randint(18, 28))):
print_same_line("#" + hashtag + ': unique photos left: ' + str(unique_photos)
+ " | Sleeping " + str(second))
time.sleep(1)
except Exception as e:
time.sleep(2)
unique_photos -= 1
if __name__ == "__main__":
username = "USERNAME"
password = "PASSWORD"
ig = InstagramBot(username, password)
ig.login()
hashtags = ['amazing', 'beautiful', 'adventure', 'photography', 'nofilter',
'newyork', 'artsy', 'alumni', 'lion', 'best', 'fun', 'happy',
'art', 'funny', 'me', 'followme', 'follow', 'cinematography', 'cinema',
'love', 'instagood', 'instagood', 'followme', 'fashion', 'sun', 'scruffy',
'street', 'canon', 'beauty', 'studio', 'pretty', 'vintage', 'fierce']
while True:
try:
# Choose a random tag from the list of tags
tag = random.choice(hashtags)
ig.like_photo(tag)
except Exception:
ig.closeBrowser()
time.sleep(60)
ig = InstagramBot(username, password)
ig.login()
@frankpitale

This comment has been minimized.

Copy link

frankpitale commented Jul 30, 2018

Great job man! but i have some struggle with permission denied with geckodriver...
could you please help me?

@tacomonster

This comment has been minimized.

Copy link
Owner Author

tacomonster commented Aug 1, 2018

Yeah, for sure.
Can you tell me if you're using windows or MAC? Also what are you attempting to do and what error is coming up?

@schneid201

This comment has been minimized.

Copy link

schneid201 commented Aug 9, 2018

Hey man whats up. Just saw you youtube video and loved it.

Can you help me with what I need to install and how to install everything?
Thanks

@sammyHa

This comment has been minimized.

Copy link

sammyHa commented Aug 16, 2018

This is great. But I have some issues with he 《《 def print_same_line(text)》》 the flush() part is giving error says statement expected found Py:DEDENT

@tacomonster

This comment has been minimized.

Copy link
Owner Author

tacomonster commented Aug 21, 2018

@sammyHa you can remove the print_same_line statement and replace it with print() instead.

@xXRobinXx

This comment has been minimized.

Copy link

xXRobinXx commented Aug 24, 2018

great work mate 👍

@locuspromo

This comment has been minimized.

Copy link

locuspromo commented Sep 18, 2018

Yo! I really need your help, if you are interested in helping a brotha out! - Call the number at the top right of locuspromo.com ... or email us...

We aint balln but woulnt be against paying you for some help.
Pretty sure you already have created what I want.

Just need a little guidance.

@happyguyrj

This comment has been minimized.

Copy link

happyguyrj commented Oct 1, 2018

Hello,

I have tried using Firefox and Chrome webdriver, but I'm getting same error as below for both of them.

AttributeError: 'module' object has no attribute 'PoolManager'

    self.driver = webdriver.Firefox()
  File "C:\Python27\lib\site-packages\selenium-3.14.1-py2.7.egg\selenium\webdriver\firefox\webdriver.py", line 169, in __init__
    remote_server_addr=self.service.service_url)
  File "C:\Python27\lib\site-packages\selenium-3.14.1-py2.7.egg\selenium\webdriver\firefox\remote_connection.py", line 23, in __init__
    RemoteConnection.__init__(self, remote_server_addr, keep_alive)
  File "C:\Python27\lib\site-packages\selenium-3.14.1-py2.7.egg\selenium\webdriver\remote\remote_connection.py", line 140, in __init__
    self._conn = urllib3.PoolManager(timeout=self._timeout)
AttributeError: 'module' object has no attribute 'PoolManager'

Can you help to overcome this issue?

@Dragaev

This comment has been minimized.

Copy link

Dragaev commented Oct 14, 2018

Hi! Tell me, please, why?

Traceback (most recent call last):
File "C:/Users/blew/PycharmProjects/train/training.py", line 75, in
ig.login()
File "C:/Users/blew/PycharmProjects/train/training.py", line 22, in login
driver.get("https://www.instagram.com/")
AttributeError: 'module' object has no attribute 'get'

@alpha876

This comment has been minimized.

Copy link

alpha876 commented Nov 19, 2018

HI!
It's going in a like and unlike loop. Can you tell me whats going on?

@occuper

This comment has been minimized.

Copy link

occuper commented Nov 23, 2018

hi
how i can change this line for click on follow button ??
like_button = lambda: driver.find_element_by_xpath('/html/body/span/section/main/div/div/article/div[2]/section[1]/span[1]/button').click()
thank u very much

@pnilssson

This comment has been minimized.

Copy link

pnilssson commented Nov 24, 2018

HI!
It's going in a like and unlike loop. Can you tell me whats going on?

Got the same problem as Alpha, anyone find out how to solve this?

@9vimu9

This comment has been minimized.

Copy link

9vimu9 commented Nov 27, 2018

thank you so much, sharing with us.
But some of your code not works for me
so here is my version

`from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time

class InstagramBot:

def __init__(self,username,password):
    self.username=username
    self.password=password
    self.driver=webdriver.Firefox()

def closrBrowser(self):
    self.driver.close()

def login(self):
    driver=self.driver
    driver.get("https://www.instagram.com/accounts/login/")
    time.sleep(10)
    user_name_element=driver.find_element_by_xpath("//input[@name='username']")
    user_name_element.clear()
    user_name_element.send_keys(self.username)

    password_element = driver.find_element_by_xpath("//input[@name='password']")
    password_element.clear()
    password_element.send_keys(self.password)
    password_element.send_keys(Keys.RETURN)
    time.sleep(25)
    cancel_notification_button = driver.find_element_by_class_name('HoLwm')
    cancel_notification_button.send_keys(Keys.RETURN)
    time.sleep(2)

def like_photo(self,hashtag):
    driver = self.driver
    driver.get("https://www.instagram.com/explore/tags/"+hashtag+"/")
    time.sleep(10)
    for i in range(1,3):
        driver.execute_script("window.scrollTo(0,document.body.scrollHeight);")
        time.sleep(5)
    #searshing for picture link
    hrefs = driver.find_elements_by_tag_name('a')
    images_links = []
    for item in hrefs:
        href = item.get_attribute('href')
        if "/p/" not in href:
            continue
        #print(href)
        images_links.append(href)

    for images_link in images_links:
        driver.get(images_link)
        driver.execute_script("window.scrollTo(0,document.body.scrollHeight);")
        try:
            driver.find_element_by_class_name("coreSpriteHeartOpen").click()
            time.sleep(10)
        except Exception as e:
            time.sleep(2)

bot=InstagramBot("username","password")
bot.login()
bot.like_photo('srilanka')
`

@muneeshdk

This comment has been minimized.

Copy link

muneeshdk commented Nov 28, 2018

hey i not understand how to pest geckodriver on Windows.
And init methode of class InstagramBote take two parameter then how ### self.driver= comes

@TheophileLuron

This comment has been minimized.

Copy link

TheophileLuron commented Nov 28, 2018

Hello guys !

for me all running good with out error !
But I do not see anything happen about the "like button" I don't know if the program like the picture I can't see nothing happened when we moves to each photos ?

Some one can answering this ? please and thanks you for your answer :)

@tacomonster

This comment has been minimized.

Copy link
Owner Author

tacomonster commented Jan 3, 2019

Hello guys !

for me all running good with out error !
But I do not see anything happen about the "like button" I don't know if the program like the picture I can't see nothing happened when we moves to each photos ?

Some one can answering this ? please and thanks you for your answer :)

Currently the Xpath should find the like button and click it if it has not been liked. If you're having trouble finding the like button replicate the method I use in the video to find the new xpath. This way you'll be able to update your code.

@studybug

This comment has been minimized.

Copy link

studybug commented Jan 20, 2019

hmmm. I cannot seem to get the code to work on my mac. Can anyone assist? It might be related to the python my computer is using?

Now I have this error message on PyCharm:
/Users/student/PycharmProjects/youtube/venv/bin/python "/Users/student/Desktop/youtube vid/instagram.py"
File "/Users/student/Desktop/youtube vid/instagram.py", line 1
import selenium from webdriver
^
SyntaxError: invalid syntax

Process finished with exit code 1

@devBhairavi

This comment has been minimized.

Copy link

devBhairavi commented Jan 23, 2019

For people Mozilla webdriver is not working please install "MOZILLA DEVELOPER EDITION" browser for it to work. Thank you

@devBhairavi

This comment has been minimized.

Copy link

devBhairavi commented Jan 23, 2019

[for second in reversed(range(0, random.randint(18, 28))):
print_same_line("#" + hashtag + ': unique photos left: ' + str(unique_photos)
+ " | Sleeping " + str(second))
time.sleep(1)](url)

What does this code actually do ? What does this for in second do ?

@hyzmael88

This comment has been minimized.

Copy link

hyzmael88 commented Jan 30, 2019

How could be if i want to like and coment "great photo"?

@tacomonster

This comment has been minimized.

Copy link
Owner Author

tacomonster commented Feb 1, 2019

[for second in reversed(range(0, random.randint(18, 28))):
print_same_line("#" + hashtag + ': unique photos left: ' + str(unique_photos)
+ " | Sleeping " + str(second))
time.sleep(1)](url)

What does this code actually do ? What does this for in second do ?

It's supposed to be a sleep countdown timer.

@antuan188

This comment has been minimized.

Copy link

antuan188 commented Feb 23, 2019

Hey, thank you for the effort to sharing your bot. I've tried the bot yesterday and it works so far except it doesn't like the pictures...

I have copied the bot 1 by 1 except line 72

like_button = lambda: driver.find_element_by_xpath('//span[@aria-label=r"Gefällt mir"]').click()

here I use r=Gefällt mir instead of "like" becaus I have only access to the german xpath.

It would be grat if you can give me some advice.

Antuan

@ghost

This comment has been minimized.

Copy link

ghost commented Mar 8, 2019

It doesn't work anymore since it can't find the like button.

@ghost

This comment has been minimized.

Copy link

ghost commented Mar 8, 2019

Exception is that Message: Unable to locate element: //span[@aria-label="Like"]

@indian-boy

This comment has been minimized.

Copy link

indian-boy commented Mar 23, 2019

@ugrcn your Chrome probably maybe in another language, check with Inspect the like button to get what word would be equals "Like" for you! Hope this could be useful to you.

Regards

@Fabian1337

This comment has been minimized.

Copy link

Fabian1337 commented Mar 23, 2019

add this in init will help:

ignore errors + set language

self.options = webdriver.ChromeOptions() self.options.add_argument('--ignore-certificate-errors') self.options.add_argument('--ignore-ssl-errors') self.options.add_argument("--lang=en-GB") self.driver = webdriver.Chrome( executable_path=r".\chromedriver.exe", chrome_options=self.options)

@kdtgal

This comment has been minimized.

Copy link

kdtgal commented Jun 11, 2019

ISSUE CLOSED!

It works most of the time, sometimes this bottom login comes up now! This might be while I am on temporary ban only, but I'm not positive.
Screen Shot 2019-06-10 at 3.12.52 PM.png

Right now one of my accounts is running, but the other one keeps running into this screen, it is such a weird situation and not exactly always repeatable so I'm not quite sure how we are going to tackle this.

The weird thing is it shows up after the bot actually logs in? Maybe this is a glitch with the Instagram site itself because it would happen only 1-100 now it happens more, and now 100% on one of my accounts!

It is working now after re-launch but wondering if anyone else noticed this and if so has a solution, or knows what is going on?

Screen Shot 2019-06-10 at 3.38.34 PM.png

The fix to this error in the first screenshot was simply clearing the cache and cookies in Firefox browser! minor! lol

The bot is working great!

@kdtgal

This comment has been minimized.

Copy link

kdtgal commented Jun 11, 2019

It doesn't work anymore since it can't find the like button.
Should not even be .click() on same line, you can even delete the .click() off the end after="Like"]' and call the like on the next line, works better that way I found! In my other bots I just have top line
like_button = lambda: driver.find_element_by_xpath('//span[@aria-label="Like"]')

This code works for me and is running right now exactly like this:

like_button = lambda: driver.find_element_by_xpath('//span[@aria-label="Like"]').click()
like_button().click()

Screen Shot 2019-06-10 at 3.47.54 PM.png

@kdtgal

This comment has been minimized.

Copy link

kdtgal commented Jun 11, 2019

Try this!

like_button = lambda: driver.find_element_by_xpath('//span[@aria-label=r"Gefällt mir"]')
like_button().click()

@hyzmael88

This comment has been minimized.

Copy link

hyzmael88 commented Jun 11, 2019

what can i do if it ask me for a code every time that i try to use the bot? :(

@kdtgal

This comment has been minimized.

Copy link

kdtgal commented Jun 12, 2019

what can i do if it ask me for a code every time that i try to use the bot? :(

You mean the 2fa? They asked me for the 2fa in the very beginning, I just put it it in once manually and then the next time I ran the bot on that computer's browser it was verified & it worked fine. Do you have some screenshots of what is going on? Maybe your ip is changing every time?

@grgrego07

This comment has been minimized.

Copy link

grgrego07 commented Jun 17, 2019

Is anyone else facing issues with logging in / liking using that bot?

@kdtgal

This comment has been minimized.

Copy link

kdtgal commented Jun 17, 2019

Strange only one of my accounts won't log in today, however I am logged in again right now! lol Maybe it is the temp Ban. What is your error message?? Post a screenshot and it would be easier to see what all the issues are.

@grgrego07

This comment has been minimized.

Copy link

grgrego07 commented Jun 17, 2019

@kdtgal i get no errors. it attempts to log in with username/pass. then it tries to find the pictures based on the hashtag and starts to loop through the pictures without liking. that is because it is not signing in.

image

@kdtgal

This comment has been minimized.

Copy link

kdtgal commented Jun 17, 2019

We don't get errors cause we are logging in and we are getting purposely routed to a new login! It means we are now blocked and need to fix our bot now. I ran into this issue after I hit 1000 followers! Gotta redo your XPaths to the new login!! Inspect your new login and update!

@kdtgal

This comment has been minimized.

Copy link

kdtgal commented Jun 19, 2019

@kdtgal i get no errors. it attempts to log in with username/pass. then it tries to find the pictures based on the hashtag and starts to loop through the pictures without liking. that is because it is not signing in.

image

Hi I tested in my Firefox and cleared my cache and cookies and it worked today!! So that is the fix!!

@grgrego07

This comment has been minimized.

Copy link

grgrego07 commented Jun 20, 2019

Thanks a lot @kdtgal is appears that is resolved now 👍

@kdtgal

This comment has been minimized.

Copy link

kdtgal commented Jul 3, 2019

It stopped working today after I updated my Mac, JUST ROTATES THROUGH HASHTAGS NOW - BOT DOWN! Not sure yet, will have to take a look later. Anyone else having this problem?

@riccop13

This comment has been minimized.

Copy link

riccop13 commented Jul 5, 2019

hello, can someone help me with this error code C:\Python\python.exe "C:/Python/Python Ex/IB.py"
Traceback (most recent call last):
File "C:/Python/Python Ex/IB.py", line 14, in
class InstagramBot:
File "C:/Python/Python Ex/IB.py", line 39, in InstagramBot
VenomSliderzIG = InstagramBot("venomsliderz","tacobelly23")
NameError: name 'InstagramBot' is not defined

Seems like the InstagramBot name and class is not valid. How to fix it? Thanks

@mothrofchrst

This comment has been minimized.

Copy link

mothrofchrst commented Jul 20, 2019

It stopped working today after I updated my Mac, JUST ROTATES THROUGH HASHTAGS NOW - BOT DOWN! Not sure yet, will have to take a look later. Anyone else having this problem?

I am also running into this (or a similar) issue now.

Everything is working fine - opens Instagram, navigates to random hashtag, opens photo, but after some time on the photo it moves on to the next without ever giving a "Like"

@M1dNi8

This comment has been minimized.

Copy link

M1dNi8 commented Aug 6, 2019

It stopped working today after I updated my Mac, JUST ROTATES THROUGH HASHTAGS NOW - BOT DOWN! Not sure yet, will have to take a look later. Anyone else having this problem?

I am also running into this (or a similar) issue now.

Everything is working fine - opens Instagram, navigates to random hashtag, opens photo, but after some time on the photo it moves on to the next without ever giving a "Like"

YOU CAN FIX BOT YOURSELF

It's a browser language issue.

You have to check, what's label name of like button in your language. (Open Code Element with right Click on Like Button on Page)

Check Line 72
like_button = lambda: driver.find_element_by_xpath('//span[@aria-label="Like"]').click()

You have to change label name: (My example for German Language)

like_button = lambda: driver.find_element_by_xpath('//span[@aria-label="Gefällt mir"]').click()


Then the Bot is like and work fine again.

@ghost

This comment has been minimized.

Copy link

ghost commented Aug 10, 2019

I'm trying to run the bot and everything's fine except when it tries to login, Instagram redirects to the 'suspicious login attempt page'. How do I deal with that?

@kowalski6ix9

This comment has been minimized.

Copy link

kowalski6ix9 commented Aug 13, 2019

Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 76, in start
stdin=PIPE)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 775, in init
restore_signals, start_new_session)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 1522, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'chromedriver': 'chromedriver'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/MEinarsson/Documents/INSTABOT.py", line 87, in
ig = InstagramBot(username, password)
File "/Users/MEinarsson/Documents/INSTABOT.py", line 20, in init
self.driver = webdriver.Chrome()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in init
self.service.start()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 83, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

@giorgio-marga

This comment has been minimized.

Copy link

giorgio-marga commented Aug 13, 2019

It worked for me, so thank you for that.
My question is: Where in the code do I set up, how many likes the bot is going to make in one minute ?

@softaim

This comment has been minimized.

Copy link

softaim commented Aug 26, 2019

I m facing lot's of Problem ............ Please help me sir

Traceback (most recent call last):
File "C:\Users\Vikas\OneDrive\Pictures\Desktop\Python-Starting\twitter-bot.py", line 87, in
ig = InstagramBot(username, password)
File "C:\Users\Vikas\OneDrive\Pictures\Desktop\Python-Starting\twitter-bot.py", line 20, in init
self.driver = webdriver.Firefox()
File "C:\Users\Vikas\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 174, in init
keep_alive=True)
File "C:\Users\Vikas\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in init
self.start_session(capabilities, browser_profile)
File "C:\Users\Vikas\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\Vikas\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\Vikas\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities

@M1dNi8

This comment has been minimized.

Copy link

M1dNi8 commented Aug 26, 2019

I m facing lot's of Problem ............ Please help me sir

Traceback (most recent call last):
File "C:\Users\Vikas\OneDrive\Pictures\Desktop\Python-Starting\twitter-bot.py", line 87, in
ig = InstagramBot(username, password)
File "C:\Users\Vikas\OneDrive\Pictures\Desktop\Python-Starting\twitter-bot.py", line 20, in init
self.driver = webdriver.Firefox()
File "C:\Users\Vikas\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 174, in init
keep_alive=True)
File "C:\Users\Vikas\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in init
self.start_session(capabilities, browser_profile)
File "C:\Users\Vikas\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\Vikas\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\Vikas\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities

Do you run a Twitter-Bot at same time?

The first lines of your error, talk about errors with twitter-bot.py in the folder Python-Starting on your desktop. A Twitter Bot have fields of that scripts here?!

Delete both bots and reinstall instagram.

@softaim

This comment has been minimized.

Copy link

softaim commented Aug 26, 2019

@M1dNi8

This comment has been minimized.

Copy link

M1dNi8 commented Aug 26, 2019

Facing Same Problem File "insta-bot.py", line 87, in ig = InstagramBot(username, password) File "insta-bot.py", line 20, in init self.driver = webdriver.Firefox() File "C:\Users\Vikas\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 174, in init keep_alive=True) File "C:\Users\Vikas\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in init self.start_session(capabilities, browser_profile) File "C:\Users\Vikas\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session response = self.execute(Command.NEW_SESSION, parameters) File "C:\Users\Vikas\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute self.error_handler.check_response(response) File "C:\Users\Vikas\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities

Use Chrome and the actually script. Think you have wrong Firefox Browser. 32bit - 64 bit. He not find ur browser.

@colorado2019

This comment has been minimized.

Copy link

colorado2019 commented Aug 30, 2019

The code is working, however after liking anywhere between 15-50 pictures it will just stop and does not move onto the next page. I will close and run again, only to have the same outcome. Changing to a different hashtag does the same thing! Any ideas?

@GuneetTalwar

This comment has been minimized.

Copy link

GuneetTalwar commented Sep 15, 2019

Great job man! but i have some struggle with permission denied with geckodriver...
could you please help me?

Anyone who has this problem.Just go and grab the executable file from the extracted geckodriver download file and place it in your project folder.That should solve your problem!!

@BrandonWalker7

This comment has been minimized.

Copy link

BrandonWalker7 commented Sep 20, 2019

Great job man! but i have some struggle with permission denied with geckodriver...
could you please help me?

Anyone who has this problem.Just go and grab the executable file from the extracted geckodriver download file and place it in your project folder.That should solve your problem!!

How is it that we grab that file? And once we do that do we not need to worry about the permission denied error in the terminal?

@GuneetTalwar

This comment has been minimized.

Copy link

GuneetTalwar commented Sep 22, 2019

extract the file and you will get an executable geckodriver file.Just copy it into your project folder.As far as permissions ar concerned it worked for me.You can try put what works best for you .

@BrandonWalker7

This comment has been minimized.

Copy link

BrandonWalker7 commented Sep 22, 2019

Screen Shot 2019-09-22 at 1 48 02 PM

Sorry for not being clear on how to extract the file. By extracting the file do you mean placing geckodriver into the same file like this instead of the desktop? Or redownloading it and having one in each spot? I have tried both of these and get the same errors. I guess I need clarification on what you are saying. Sorry, I'm a noob. @GuneetTalwar
@snicodimescu

This comment has been minimized.

Copy link

snicodimescu commented Nov 13, 2019

It didn't work at first from the source code as of 13/11/19.

However, I got it to work by changing line 20 from 'self.driver = webdriver.Chrome()' to 'self.driver = webdriver.Firefox()'.

Works like a charm so far since I made that change.

Don't forget to change your username/password and the hashtags if you want.

@itsrhed

This comment has been minimized.

Copy link

itsrhed commented Nov 18, 2019

How do you manage to prevent "Action Blocked" by instagram after a number of likes? I keep getting this within 30mins or less and have to wait for like a day in order to like again. In one case, instagram also asked me to change my password because of a "suspicious login, activities". Anyone having these issues?

@GuneetTalwar

This comment has been minimized.

Copy link

GuneetTalwar commented Nov 18, 2019

@MrHarreh

This comment has been minimized.

Copy link

MrHarreh commented Nov 18, 2019

I'm running this bot a project of mine, however after about 1/2 hours of the bot running I get blocked on Instagram as voilating terms of service. I suspect it's because of the amount it is liking during a time period. Anyone had success without getting blocked?

@ajmalfaiz

This comment has been minimized.

Copy link

ajmalfaiz commented Nov 20, 2019

How to setup autocomment too with it

@5sfayas

This comment has been minimized.

Copy link

5sfayas commented Nov 30, 2019

wow. it's really awesome! I changed the code as per my need. still, I need to change liking pattern.
the bot like photos from the top. I want you to randomize liking (for pic_href in pic_hrefs: driver.get(pic_href))
please add headless chrome bot like also

@huzoorbux

This comment has been minimized.

Copy link

huzoorbux commented Dec 3, 2019

"Action Blocked" after 20+ likes :(

@poptart3697

This comment has been minimized.

Copy link

poptart3697 commented Dec 3, 2019

Out of all of the instagram bots I've found, this is by far the best one. Thank you for this! Works perfectly.

@kdtgal

This comment has been minimized.

Copy link

kdtgal commented Dec 3, 2019

@dvilardi

This comment has been minimized.

Copy link

dvilardi commented Dec 4, 2019

Why not navigate directly to the login page instead of dealing with extra buttons?

driver.get("https://www.instagram.com/accounts/login/")

@eugenefauntleroy

This comment has been minimized.

Copy link

eugenefauntleroy commented Dec 20, 2019

Browser crashes as soon as log in is executed, and then as commanded opens back up and just repeats process. Any tips would be appreciated.

@Rajeshwari09

This comment has been minimized.

Copy link

Rajeshwari09 commented Dec 22, 2019

Sir I am making a LinkedIn bot using your guidance from your code and but it Stops working after thired login dude to bot detection .
Sir please can you help me with this .

@mr-landerson1

This comment has been minimized.

Copy link

mr-landerson1 commented Dec 24, 2019

https://discord.gg/3JB2qPn

Selenium automation group

@poptart3697

This comment has been minimized.

Copy link

poptart3697 commented Jan 18, 2020

Hello! I have been running this bot without any issues for months, but just today it stopped working correctly. The bot no longer likes the photos, it just goes from photo to photo without completing the "like" action. I'm not sure if Instagram changed their HTML or why it is doing this but any feedback would be appreciated!

@git-aishgupta

This comment has been minimized.

Copy link

git-aishgupta commented Jan 29, 2020

Hello! I have been running this bot without any issues for months, but just today it stopped working correctly. The bot no longer likes the photos, it just goes from photo to photo without completing the "like" action. I'm not sure if Instagram changed their HTML or why it is doing this but any feedback would be appreciated!

I am facing the same issue. Did you figure out the solution?

@poptart3697

This comment has been minimized.

Copy link

poptart3697 commented Jan 30, 2020

Here is my solution: I had to change the code for liking to find the class instead of xpath.
I changed it to: "like_button = lambda: driver.find_element_by_class_name("_8-yf5 ").click()"

@walter-grace

This comment has been minimized.

Copy link

walter-grace commented Feb 6, 2020

Here is my solution: I had to change the code for liking to find the class instead of xpath.
I changed it to: "like_button = lambda: driver.find_element_by_class_name("_8-yf5 ").click()"

This worked for me; I was having issues with the bot liking post this fixed it.

@kobojp

This comment has been minimized.

Copy link

kobojp commented Feb 18, 2020

I am a beginner
Why use lambda
lambda: driver.find_element_by_xpath('//span[@aria-label="Like"]').click()

@juand07

This comment has been minimized.

Copy link

juand07 commented Mar 18, 2020

ISSUE CLOSED!

It works most of the time, sometimes this bottom login comes up now! This might be while I am on temporary ban only, but I'm not positive.
Screen Shot 2019-06-10 at 3.12.52 PM.png

Right now one of my accounts is running, but the other one keeps running into this screen, it is such a weird situation and not exactly always repeatable so I'm not quite sure how we are going to tackle this.

The weird thing is it shows up after the bot actually logs in? Maybe this is a glitch with the Instagram site itself because it would happen only 1-100 now it happens more, and now 100% on one of my accounts!

It is working now after re-launch but wondering if anyone else noticed this and if so has a solution, or knows what is going on?

Screen Shot 2019-06-10 at 3.38.34 PM.png

The fix to this error in the first screenshot was simply clearing the cache and cookies in Firefox browser! minor! lol

The bot is working great!

Hi, I deleted the cache in Firefox but it still has the same error, and I don't know what to do with this problem.

screenshot_20200317-223236_1366x768

Do you have any ideas?

@HimanshuMishra1123

This comment has been minimized.

Copy link

HimanshuMishra1123 commented Apr 8, 2020

This works perfectly aside from not liking the posts it goes to :/
It just goes from post to posts but doesn't like the posts...
I tried copying the full xpath and finding by class name
(didn't try to change label name to german one since the language of the browser is english by default)
but it didn't work :/

what should I do to fix it?

@theN0N3N717Yone

This comment has been minimized.

Copy link

theN0N3N717Yone commented Apr 9, 2020

This works perfectly aside from not liking the posts it goes to :/
It just goes from post to posts but doesn't like the posts...
I tried copying the full xpath and finding by class name
(didn't try to change label name to german one since the language of the browser is english by default)
but it didn't work :/

what should I do to fix it?

Hey, i got the same problem but fixed it by {{ like_button = lambda: driver.find_element_by_class_name("_8-yf5 ").click() }} instead of {{ like_button = lambda: driver.find_element_by_xpath('//span[@aria-label="Like"]').click() }}

@nitesh122

This comment has been minimized.

Copy link

nitesh122 commented Apr 18, 2020

I have an error that is
Traceback (most recent call last)
in
Import error : cannot import name 'keys' from 'selenium.webdriver.common.keys' (C:users\ anaconda3\site-packages\webdriver\common\keys.py)
Can you help me sir

@nitesh122

This comment has been minimized.

Copy link

nitesh122 commented Apr 18, 2020

I have an error that is
Traceback (most recent call last)
in
Import error : cannot import name 'keys' from 'selenium.webdriver.common.keys' (C:users\ anaconda3\site-packages\webdriver\common\keys.py)
Please help me sir...

@danial202020

This comment has been minimized.

Copy link

danial202020 commented May 3, 2020

hey bro thanks for your help and everything I have an issue my code logs in Instagram but it dose not go for hashtags and stuff as well as I don't get any error do you know by any chance what is the problem with that
?

best regards

@RGV2

This comment has been minimized.

Copy link

RGV2 commented May 6, 2020

hey bro thanks for your help and everything I have an issue my code logs in Instagram but it dose not go for hashtags and stuff as well as I don't get any error do you know by any chance what is the problem with that
?

best regards

Hi Danial, replace the line 57 with if '/p/' in elem.get_attribute('href')] i.e.,, remove the .com part.
Hope this will help you.

@danial202020

This comment has been minimized.

Copy link

danial202020 commented May 7, 2020

hey bro thanks for the response but I changed it and still its same thing do you know by any chance why is it ?

@RGV2

This comment has been minimized.

Copy link

RGV2 commented May 8, 2020

hey bro thanks for the response but I changed it and still its same thing do you know by any chance why is it ?

Hi Danial, you can use my repo InstaBot which is working fine.

@crushsoccer

This comment has been minimized.

Copy link

crushsoccer commented May 8, 2020

Hey i go this error message can anyone help me with it?

Traceback (most recent call last):
File "C:/Users/qiuan/PycharmProjects/untitled1/Python2 Class/Instagram-Bot.py", line 1, in
from selenium import webdriver
ModuleNotFoundError: No module named 'selenium'

@crushsoccer

This comment has been minimized.

Copy link

crushsoccer commented May 8, 2020

i checked with cmd that i did download selenium. This error occured after i switched the python interpretor in pycharm

@MrHarreh

This comment has been minimized.

Copy link

MrHarreh commented May 12, 2020

My code has randomly stopped login in.
I get to the login page and get the error:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//a[@href='/accounts/login/?source=auth_switcher']"}

Working fine for about a month and now nothing

@sophiabricker

This comment has been minimized.

Copy link

sophiabricker commented May 22, 2020

Everything is working fine for me, but the only problem is, the bot doesn't like the pictures as it's going through them... I've tried inspecting the like button to see if it's different from your code, but it's not. I'm not sure why this is happening. Could you possibly help please?

@RGV2

This comment has been minimized.

Copy link

RGV2 commented May 22, 2020

It is recommended to all the users not to maximize or change the size of the Chrome after running the script, because it change the fromat of the page and xPaths.

@RGV2

This comment has been minimized.

Copy link

RGV2 commented May 22, 2020

Everything is working fine for me, but the only problem is, the bot doesn't like the pictures as it's going through them... I've tried inspecting the like button to see if it's different from your code, but it's not. I'm not sure why this is happening. Could you possibly help please?

I hope this code will help you:
https://github.com/mushtaqashhar/InstaBot/blob/master/InstagramBot.py

@sophiabricker

This comment has been minimized.

Copy link

sophiabricker commented May 22, 2020

Everything is working fine for me, but the only problem is, the bot doesn't like the pictures as it's going through them... I've tried inspecting the like button to see if it's different from your code, but it's not. I'm not sure why this is happening. Could you possibly help please?

I hope this code will help you:
https://github.com/mushtaqashhar/InstaBot/blob/master/InstagramBot.py

Thank you! I got it all figured out and it works great! :)

@bumbleben21

This comment has been minimized.

Copy link

bumbleben21 commented Jul 4, 2020

Got the same problem as sophiabricker ... Everything is working fine for me, but the only problem is the bot doesn't like the pictures as it's going through them. Didn't change size of the Crome after running the script. Can you help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.