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
相关推荐
2301_793804694 分钟前
用Python和Twilio构建短信通知系统
jvm·数据库·python
B站_计算机毕业设计之家6 分钟前
计算机毕业设计:Python当当网图书数据全链路处理平台 Django框架 爬虫 Pandas 可视化 大数据 大模型 书籍(建议收藏)✅
爬虫·python·机器学习·django·flask·pandas·课程设计
我是永恒14 分钟前
上架一个跨境工具导航网站
前端
不要秃头的小孩14 分钟前
力扣刷题——111.二叉树的最小深度
数据结构·python·算法·leetcode
电子羊19 分钟前
Spec 编程工作流文档
前端
GISer_Jing25 分钟前
从CLI到GUI桌面应用——前端工程化进阶之路
前端·人工智能·aigc·交互
我是鶸26 分钟前
secml-malware python library 源码分析及实践
开发语言·python
还是大剑师兰特42 分钟前
Vue3 报错:computed value is readonly 解决方案
前端·vue.js
leaves falling1 小时前
有效的字母异位词
java·服务器·前端
进击的小头1 小时前
第15篇:MPC的发展方向及展望
python·算法