當我嘗試選擇過濾器中的所有專案時,只有當我手動滾動它時才會選擇它,如果不僅選擇了幾個無需滾動即可看到的選項,如何在美食中選擇 swiggy 過濾器中的所有選項?
uj5u.com熱心網友回復:
此代碼回圈過濾器串列并在必要時使用 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()
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/478021.html
