js执行页面滚动的操作

import time
# 执行页面滚动的操作
def drop_down():
    for m in range(1, 100, 4):  # 1 5 9 在不断的下拉过程,页面高度也会变化
        time.sleep(1)
        n = m / 9  # 1/9 5/9 9/9
        # document.documentElement.scrollTop  指定滚动条的位置
        # document.documentElement.scrollHeight 获取浏览器页面的最大高度
        js = 'document.documentElement.scrollTop = document.documentElement.scrollHeight + %f' % n
        driver.execute_script(js)

以上自定义函数运行时,会将页面慢慢下滑到最下面,在selenium中会使用到。

猜你喜欢

转载自blog.csdn.net/knighthood2001/article/details/120058091