gpt4 book ai didi

python - Selenium python无法向下滚动

转载 作者:行者123 更新时间:2023-11-28 21:11:29 25 4
gpt4 key购买 nike

尝试使用 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)

关于python - Selenium python无法向下滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35290451/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com