Пытаюсь автоматизировать лайк по хэштэгам в инсте, но когда дело доходит до того, чтобы поставить лайк выходит следующая ошибка
(selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element:{"method":"xpath","selector":"/html/body/div[1]/section/main/div/div[1]/article/div/div[3]/div/div/section[1]/span[1]/button"}
(Session info: chrome=94.0.4606.61))
Код на Python:
import random
import time
from selenium.webdriver.common.keys import Keys
from auth import login, password
from selenium import webdriver
from selenium.webdriver.common.by import By
def login_chrome (login, passwrod):
global browser
browser = webdriver.Chrome()
browser.get("https://www.instagram.com/?hl=ru")
time.sleep(random.randrange(2,4))
_login = browser.find_element(By.NAME, "username")
_login.clear()
_login.send_keys(login)
time.sleep(random.randrange(2,4))
_password = browser.find_element(By.NAME, "password")
_password.clear()
_password.send_keys(password)
time.sleep(random.randrange(2,4))
_password.send_keys (Keys.ENTER)
def hashtag (hashtag):
global browser
browser.get(f"https://www.instagram.com/explore/tags/{hashtag}/")
time.sleep(2)
for i in range (1,5):
browser.execute_script("window.scrollTo(0, document.body.scrollHeight);")
time.sleep(2)
hrefs = browser.find_elements_by_tag_name("a")
urls = [item.get_attribute('href') for item in hrefs if "/p/" in item.get_attribute('href')]
print(urls)
for url in urls:
browser.get(url)
time.sleep(random.randrange(2, 5))
like = browser.find_element(By.XPATH,"/html/body/div[1]/section/main/div/div[1]/article/div/div[3]/div/div/section[1]/span[1]/button")
like.click()
time.sleep(random.randrange(85, 105))
login_chrome(login, password)
time.sleep(5)
hashtag ("beautiful")