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
相关推荐
海鸥两三23 分钟前
uniapp 小程序引入 uview plus 框架,获得精美的UI框架
前端·vue.js·ui·小程序·uni-app
lightgis1 小时前
16openlayers加载COG(云优化Geotiff)
前端·javascript·html·html5
fish_study_csdn1 小时前
Python内存管理机制
开发语言·python·c python
小飞大王6661 小时前
TypeScript核心类型系统完全指南
前端·javascript·typescript
你的人类朋友3 小时前
✍️记录自己的git分支管理实践
前端·git·后端
java1234_小锋3 小时前
[免费]基于Python的农产品可视化系统(Django+echarts)【论文+源码+SQL脚本】
python·信息可视化·django·echarts
Danceful_YJ3 小时前
31.注意力评分函数
pytorch·python·深度学习
合作小小程序员小小店4 小时前
web网页开发,在线考勤管理系统,基于Idea,html,css,vue,java,springboot,mysql
java·前端·vue.js·后端·intellij-idea·springboot
程序员三藏4 小时前
快速弄懂POM设计模式
自动化测试·软件测试·python·selenium·测试工具·设计模式·职场和发展
防火墙在线4 小时前
前后端通信加解密(Web Crypto API )
前端·vue.js·网络协议·node.js·express