Open malijani opened 6 years ago
i fixed last issue with commenting "driver.maximize_window()". now i have a problem with the new version of IG Web! there's a window after the auth page! it's about notification :
and the error that shows when this window pops up :
Traceback (most recent call last): File "./instabot.py", line 38, indriver.find_element_by_xpath('./html/body/div[2]/div/div/div/div[3]/button[1]').click() File "/home/virtualdemon/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 394, in find_element_by_xpath return self.find_element(by=By.XPATH, value=xpath) File "/home/virtualdemon/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 978, in find_element 'value': value})['value'] File "/home/virtualdemon/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute self.error_handler.check_response(response) File "/home/virtualdemon/.local/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"./html/body/div[2]/div/div/div/div[3]/button[1]"} (Session info: chrome=70.0.3538.77) (Driver info: chromedriver=2.43.600233 (523efee95e3d68b8719b3a1c83051aa63aa6b10d),platform=Linux 4.15.0-20-generic x86_64)
the script is working now :
#!/usr/bin/env python2 # -*- coding: utf-8 -*- """ Created on Tue Oct 23 20:16:34 2018 @author: kia """ import time import random from selenium import webdriver from selenium.webdriver.common.keys import Keys userName = "Username" password = "Password" print("\033[1;32;40m ------------------------------------------") print("\033[1;32;40m - INSTAGRAM LIKER -") print("\033[1;32;40m - version 1.0 -") print("\033[1;32;40m - -") print("\033[1;32;40m - -") print("\033[1;32;40m - -") print("\033[1;32;40m - Kia Hamedi -") print("\033[1;32;40m - kia.arta9793@gmail.com -") print("\033[1;32;40m ------------------------------------------") url = 'https://www.instagram.com/accounts/login/?source=auth_switcher' driver = webdriver.Chrome('./chromedriver') #driver.maximize_window() driver.get(url) time.sleep(1) print("\033[1;32;40m-->Start") driver.find_element_by_xpath("//input[@name='username']").send_keys(userName) driver.find_element_by_xpath("//input[@name='password']").send_keys(password) time.sleep(2) driver.find_element_by_xpath('//*[@id="react-root"]/section/main/div/article/div/div[1]/div/form/div[3]/button').click() time.sleep(8) print("\033[1;32;40m-->Login") driver.find_element_by_xpath('./html/body/div/div/div/div/div[3]/button[2]').click() time.sleep(1) rand = random.randrange(1,100) print("\033[1;32;40m-->"+str(rand)+" Post Selected") for i in range(1,rand): likeElement = driver.find_element_by_xpath('//*[@id="react-root"]/section/main/section/div/div[1]/div/article['+str(i)+']/div[2]/section[1]/span[1]/button') time.sleep(1) #driver.execute_script("return arguments[0].scrollIntoView(true);", likeElement) likeElement.click() time.sleep(1) print("\033[1;32;40m-->"+str(i)+" Post Liked") print("\033[1;32;40m-->Finish") time.sleep(1) driver.close()
but it just like 8 posts... so there's a logical problem. i can't find it.... the error is :
-->Start -->Login -->33 Post Selected -->1 Post Liked -->2 Post Liked -->3 Post Liked -->4 Post Liked -->5 Post Liked -->6 Post Liked -->7 Post Liked -->8 Post Liked Traceback (most recent call last): File "instabot.py", line 43, inlikeElement = driver.find_element_by_xpath('//*[@id="react-root"]/section/main/section/div/div[1]/div/article['+str(i)+']/div[2]/section[1]/span[1]/button') File "/home/virtualdemon/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 394, in find_element_by_xpath return self.find_element(by=By.XPATH, value=xpath) File "/home/virtualdemon/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 978, in find_element 'value': value})['value'] File "/home/virtualdemon/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute self.error_handler.check_response(response) File "/home/virtualdemon/.local/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="react-root"]/section/main/section/div/div[1]/div/article[9]/div[2]/section[1]/span[1]/button"} (Session info: chrome=70.0.3538.77) (Driver info: chromedriver=2.43.600233 (523efee95e3d68b8719b3a1c83051aa63aa6b10d),platform=Linux 4.15.0-20-generic x86_64)
You can reduce the number of random numbers for posts. Also increase the time remaining for the likes of one second and re-test.
first of all thank you kia. :heart: there's something wrong i think! please add "install chromium and use chromedriver and change my absolute path in script for your chromedriver path!" into README.md when i run script with python2 :
i was installed 'python-pip' and 'selenium' library... i totally need some extra codes :laughing: . can you add a feature to like all posts from someone or all of my followers?