Thursday 21 October 2021

Scroll to bottom of infinity scrolling page

I have already read this answer, however, I need to scroll the webpage in steps, because if I scroll it directly to the height of the documents the images are not loaded, only a placeholder in base64url. I would like to scroll by a little until I get to the end of the webpage, making sure that I can see in the driver the images, so they are loaded.

Any way to achieve this?

My current function:

def scroll_to_bottom(driver):
    last_height = driver.execute_script("return document.body.scrollHeight")
    while True:
        # Scroll down to bottom
        driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
        # Wait to load page
        time.sleep(2)
        # Calculate new scroll height and compare with last scroll height
        new_height = driver.execute_script("return document.body.scrollHeight")
        if new_height == last_height:
            break
        last_height = new_height

This goes directly to te bottom, but if the item is not focused for a elapsed time it won't load the images I need.



from Scroll to bottom of infinity scrolling page

No comments:

Post a Comment