【问题标题】:Python selenium - How to access the inner scroll inside the main scrollPython selenium - 如何访问主滚动内的内部滚动
【发布时间】:2022-01-19 16:21:32
【问题描述】:

我正在尝试抓取网站中的所有数据,如图所示。 为此,我需要继续向下滚动无限滚动。但我无法访问内卷轴。我使用以下代码进行无限滚动

last_height = driver.execute_script("return document.body.scrollHeight")
while True:
    driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
    time.sleep(3)
    new_height = driver.execute_script("return document.body.scrollHeight")
    if new_height == last_height:
        break
    last_height = new_height

它不起作用。它向下滚动主外部滚动而不是内部滚动,如下所示。请帮我向下滚动内部滚动

【问题讨论】:

    标签: python python-3.x selenium web-scraping infinite-scroll


    【解决方案1】:

    1 你必须找到可滚动的元素。

    试试这些建议

    Find first scrollable parent

    2 然后

    scrollable_element = driver.find_element... # locate using css or xpath the element, found during point 1 research
    
    driver.execute_script("arguments[0].scroll(0, arguments[0].scrollHeight);", scrollable_element)
    
    

    【讨论】:

      猜你喜欢
      • 2021-01-19
      • 2017-11-26
      • 1970-01-01
      • 1970-01-01
      • 2021-06-20
      • 2022-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多