- прокрутить страницу вниз
- очистить информацию
- перейти на следующую страницу
- повторить.
Вот минимальный код, представляющий нумерацию страниц:
Код: Выделить всё
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 selenium.common.exceptions import TimeoutException
import time
URL = "https://web.archive.org/web/20230203123249/https://www.coinpeople.com/forum/64-new-member-information-and-welcome33/"
driver = webdriver.Chrome()
driver.get(URL)
time.sleep(5)
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
time.sleep(2)
while True:
try:
next_page = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, '//*[@id="elPagination_30a5535a7a65933469c1ef7e81dc96e0_806040338"]/li[9]/a'))
)
next_page.click()
except TimeoutException:
print("No more pages to click.")
break
driver.quit()
Код: Выделить всё
next_page = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, f'("a[rel='next']")')))
Код: Выделить всё
driver.execute_script("document.querySelector('[rel=next]').click();")
Код: Выделить всё
//*[@id="elPagination_30a5535a7a65933469c1ef7e81dc96e0_806040338"]/li[9]/a
//*[@id="elPagination_f4be6b25f47a268e848f4596d5b1e3a6_66137219"]/li[10]/a
//*[@id="elPagination_728dd0ae3583cbafa454d08121ab9841_298843258"]/li[11]/a
Подробнее здесь: https://stackoverflow.com/questions/792 ... -each-page