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
相关推荐
一次旅行7 分钟前
CSRF和SSRF
前端·网络·csrf
徐先生 @_@|||12 分钟前
时间序列异常检测框架CrossAD论文阅读
经验分享·python·机器学习
昱宸星光17 分钟前
spring cloud gateway内置网关filter
java·服务器·前端
宁雨桥25 分钟前
浏览器渲染原理
前端·浏览器·原理
Moment25 分钟前
此 KFC 不是肯德基,Kafka、Flink、ClickHouse 怎么搭、何时省掉 Flink
前端·后端·面试
weixin_3954489128 分钟前
build_fsd_luyan_from_rm.py-cursor0225
开发语言·python
先做个垃圾出来………28 分钟前
Python常见文件操作
linux·数据库·python
电化学仪器白超31 分钟前
EC20CEHDLG-128-SNNS调试记录
python·单片机·嵌入式硬件·自动化
极客小张32 分钟前
基于STM32的智能水质监测与远程预警系统设计与实现
c语言·python·stm32·单片机·嵌入式硬件·物联网