Код: Выделить всё
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from time import sleep
def iterar_botao():
botoes = driver.find_elements(By.CSS_SELECTOR, "a[data-dt-idx]")
qtd_botoes = len(botoes)
for i in range(qtd_botoes):
clicar_botao(str(i+1))
def clicar_botao(idx):
try:
localizador = (By.CSS_SELECTOR, f'a[data-dt-idx="{idx}"]')
botao = WebDriverWait(driver, 10).until(EC.presence_of_element_located(localizador))
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
sleep(1)
driver.execute_script("arguments[0].scrollIntoView({behavior:'instant', block:'center' });", botao)
driver.execute_script("arguments[0].click();", botao)
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "table-dividends-history")))
pegar_tabelas() # Function to scrape the tables (not shown here)
except Exception as e:
print(f"Failed to execute function: {e}")
Failed to execute function: Message: RemoteError@chrome://remote/content/shared/RemoteError.sys.mjs:8:8
WebDriverError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:199:5
NoSuchElementError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:552:5
Подробнее здесь: https://stackoverflow.com/questions/797 ... tween-numb