【问题标题】:How to get current scroll height in selenium python如何在 selenium python 中获取当前滚动高度
【发布时间】:2023-03-16 21:50:01
【问题描述】:

我想在 selenium python 中获取当前滚动高度 比如如果我在堆栈溢出的中间滚动,所以我想要在 python 中使用 selenium 时的当前滚动高度 谢谢 这个我试过了

height =  browser.execute_script("return document.body.scrollHeight")

【问题讨论】:

标签: python selenium web-scraping selenium-chromedriver


【解决方案1】:

试试这个:

height = browser.execute_script("return document.documentElement.scrollHeight")

【讨论】:

    【解决方案2】:

    要获得页面滚动高度,您可以使用以下代码

    height = int(driver.execute_script("return document.documentElement.scrollHeight"))
    

    但是如果你想获取当前位置的滚动高度,就必须使用。

    totalScrolledHeight = driver.execute_script("return window.pageYOffset + window.innerHeight")
    

    参考:Selenium Scroll Current Position

    【讨论】:

      猜你喜欢
      • 2013-04-05
      • 2020-03-18
      • 1970-01-01
      • 1970-01-01
      • 2014-06-30
      • 2014-09-07
      • 1970-01-01
      • 2012-08-20
      相关资源
      最近更新 更多