python Selenium控制浏览器自动下拉到底部,实现网页资源全加载

def scroll_to_bottom(self, driver):
    """控制浏览器自动拉倒底部"""

    js = "return action=document.body.scrollHeight"
    # 初始化现在滚动条所在高度为0
    height = 0
    # 当前窗口总高度
    new_height = driver.execute_script(js)

    while height < new_height:
        # 将滚动条调整至页面底部
        for i in range(height, new_height, 100):
            driver.execute_script('window.scrollTo(0, {})'.format(i))
            time.sleep(0.2)
        height = new_height
        time.sleep(0.1)
        new_height = driver.execute_script(js)

猜你喜欢

转载自blog.csdn.net/Stybill_LV_/article/details/111183750
今日推荐