from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.options import Options
url = 'https://www.avito.ru/sankt-peterburg/noutbuki?cd=1'
options = Options()
options.page_load_strategy = 'eager'
driver = webdriver.Firefox(options=options)
driver.get(url)
count_pages_old = int(driver.find_elements(By.CLASS_NAME, 'pagination-item-JJq_j')[-2].text)
driver.get(f'{url}&p={count_pages_old}')
count_pages = int(driver.find_elements(By.CLASS_NAME, 'pagination-item-JJq_j')[-2].text)
original_window = driver.current_window_handle
print(f'Создаем {count_pages} вкладок')
for num_page in range(1, count_pages + 2):
driver.switch_to.new_window('tab')
page = 1
for window_handle in driver.window_handles:
driver.switch_to.window(window_handle)
print(f'Открываем страницу {page}')
driver.get(f"{url}&p={page}")
page += 1