Python&;Selenium:向下滚动以避免广告重叠,然后单击按钮

Python&;Selenium:向下滚动以避免广告重叠,然后单击按钮,python,selenium,Python,Selenium,我尝试循环浏览页面,但我的页面数按钮上有重叠广告 我的浏览器上有这个,页面按钮位于“DocuSign”广告的后面: 所以我试图向下滚动,以便能够点击下一页,但它不起作用 我希望能够点击以下页面: 我试过这个: import time from selenium import webdriver from selenium.common.exceptions import NoSuchElementException from selenium.webdriver.support.ui im

我尝试循环浏览页面,但我的页面数按钮上有重叠广告

我的浏览器上有这个,页面按钮位于“DocuSign”广告的后面:

所以我试图向下滚动,以便能够点击下一页,但它不起作用

我希望能够点击以下页面:

我试过这个:

import time

from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains

driver = webdriver.Chrome(executable_path="/Users/name/Downloads/chromedriver 4")
url = 'http://www.legorafi.fr/category/france/politique'
driver.get(url)

WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"div#appconsent>iframe")))
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.button--filled>span.baseText"))).click()

page_number = 1
while True:
    driver.execute_script("window.scrollTo(0,document.body.scrollHeight)")
    time.sleep(3)
    try: 
        link = driver.find_element_by_xpath('//*[@id="main"]/div[5]/div/a[1]')
    except NoSuchElementException:
        break
    link.click()
    print(driver.current_url)
    page_number += 1

您可以尝试更恰当地查找“下一页”按钮

driver.find_elements_by_xpath("//*[contains(text(), 'Next Page')]")

谢谢,这是一个更好的解决方案。更易于使用