这段代码在过滤器列表上循环,并在必要时使用javascript向下滚动.
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
driver = webdriver.Chrome(service=Service(chromedriver_path))
...do something and then open the Filters sidebar...
# loop over the filters and scroll if necessary
for box in driver.find_elements(By.CSS_SELECTOR, 'input[type=checkbox] + span'):
driver.execute_script('arguments[0].scrollIntoView({block: "center"});', box)
box.click()