selenium滚动到页面底部

selenium页面滚动加载到底部

python 复制代码
import time

# 方法:滚动到页面底部
def scroll_to_bottom(driver):
    last_height = driver.execute_script("return document.documentElement.scrollHeight")
    print(f"Initial Document Height: {last_height}")

    while True:
        print("Scrolling down...")
        # 向页面底部滚动
        driver.execute_script("window.scrollTo(0, document.documentElement.scrollHeight);")

        # 等待页面加载
        time.sleep(3)

        # 获取新的页面高度
        new_height = driver.execute_script("return document.documentElement.scrollHeight")
        print(f"New Document Height: {new_height}")

        # 如果新高度和旧高度相同,说明已经到底
        if new_height == last_height:
            print("Reached bottom of the page.")
            break

        last_height = new_height
相关推荐
才兄说16 小时前
机器人二次开发机器狗巡检?定位精度±2cm
python
2301_7826591816 小时前
SQL视图能否用于数据仓库模型_雪花模型与视图构建
jvm·数据库·python
m0_3776182316 小时前
CSS如何让文字超出两行显示省略号_使用line-clamp属性限制
jvm·数据库·python
m0_7436239216 小时前
HTML5中LocalStorage存储用户自定义快捷键配置
jvm·数据库·python
用户4124675083717 小时前
用 Locust 压测一个网站,记录一下学习过程
前端
2301_7735536217 小时前
HTML5中SharedWorker生命周期与浏览器进程关闭的关系
jvm·数据库·python
m0_6403093017 小时前
mysql flush privileges有什么作用_mysql权限生效机制解析
jvm·数据库·python
2401_8971905517 小时前
mysql备份期间如何监控系统负载_使用iostat与top命令
jvm·数据库·python
2301_7965885017 小时前
SQL批量删除不同条件的记录_使用IN子句简化删除逻辑
jvm·数据库·python
m0_6845019817 小时前
Golang如何解析嵌套JSON_Golang嵌套JSON解析教程【简明】
jvm·数据库·python