I try to autofollow in Instagram 30 people in a list with xpath and selenium and everybody has the same class, except of them i already followed. When the programm autofollows via class and gets one i already followed it stops. How can i let the program skip the class, if its not the one it is searching?
Thats the statement where it follows the people.
for i in range (1, 31):
browser.find_element_by_xpath("//button[@class='sqdOP L3NKy y3zKF ']").click()
print(i)
I already tried this but that also wont work
def follower():
for i in range (1, 31):
try:
browser.find_element_by_xpath("//button[@class='sqdOP L3NKy y3zKF ']").click()
print(i)
except:
continue
You can try it yourself, dont forget to change the login information (Line 12&13)
from selenium import webdriver
from time import sleep
browser = webdriver.Chrome()
url = "https://www.instagram.com/"
browser.get(url)
sleep(1)
browser.find_element_by_xpath("/html/body/div[2]/div/div/div/div[2]/button[1]").click()
#Login
browser.find_element_by_xpath("/html/body/div[1]/section/main/article/div[2]/div[1]/div/form/div/div[1]/div/label/input").send_keys("Username")
browser.find_element_by_xpath("/html/body/div[1]/section/main/article/div[2]/div[1]/div/form/div/div[2]/div/label/input").send_keys("Password")
browser.find_element_by_xpath("/html/body/div[1]/section/main/article/div[2]/div[1]/div/form/div/div[3]/button").click()
sleep(3)
browser.find_element_by_xpath("/html/body/div[1]/section/main/div/div/div/div/button").click()
browser.find_element_by_xpath("/html/body/div[4]/div/div/div/div[3]/button[2]").click()
url = "https://www.instagram.com/scarlxrd/"
browser.get(url)
browser.find_element_by_xpath("/html/body/div[1]/section/main/div/div[3]/article/div/div/div[1]/div[1]/a/div/div[2]").click()#Bildwahl
sleep(1)
try:
browser.find_element_by_xpath("/html/body/div[5]/div[2]/div/article/div[3]/section[2]/div/div[2]/a").click()
except:
browser.find_element_by_xpath("/html/body/div[5]/div[2]/div/article/div[3]/section[2]/div/div/a").click()
sleep(1)
for i in range (1, 31):
try:
browser.find_element_by_xpath("//button[@class='sqdOP L3NKy y3zKF ']").click()
print(i)