尝试使用selenium-webdriver python向下滚动到页面底部,以便加载更多产品。
driver = webdriver.Firefox() driver.get('https://www.woolworths.com.au/Shop/Browse/back-to-school/free-school-labels') driver.implicitly_wait(100) driver.execute_script("window.scrollTo(0, document.body.scrollHeight);") time.sleep(100) driver.quit()
该网页已加载,但没有变化。
我想念什么吗?
您可以尝试以下move_up和move_down函数:
driver.maximize_window() driver.get('https://www.woolworths.com.au/Shop/Browse/back-to-school/free-school-labels') driver.implicitly_wait(15) centerPanel = driver.find_element_by_css_selector("#center-panel > div[class*='hideScroll-wrapper']") jsScript = """ function move_up(element) { element.scrollTop = element.scrollTop - 1000; } function move_down(element) { element.scrollTop = element.scrollTop + 1000; } move_down(arguments[0]); move_down(arguments[0]); """ driver.execute_script(jsScript, centerPanel) time.sleep(3) jsScript = """ function move_up(element) { element.scrollTop = element.scrollTop - 1000; } function move_down(element) { console.log('Position before: ' + element.scrollTop); element.scrollTop = element.scrollTop + 1000; console.log('Position after: ' + element.scrollTop); } move_up(arguments[0]); """ driver.execute_script(jsScript, centerPanel)