0

so I got this script that scrolls endlessly in an infinite loading page but its too fast I need to to be slower and give images time to load

from webdriver_manager.chrome import ChromeDriverManager
from time import*

driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get("https://scrolller.com/")


while driver.find_element_by_tag_name('div'):
    driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
    Divs=driver.find_element_by_tag_name('div').text
    if 'End of Results' in Divs:
        print('end')
        break
    else:
        continue```
YouAgain
  • 1
  • 1

1 Answers1

0

Try this solution:

driver.execute_async_script(
            """
        count = 400;
        let callback = arguments[arguments.length - 1];
        t = setTimeout(function scrolldown(){
            console.log(count, t);
            window.scrollTo(0, count);
            if(count < (document.body.scrollHeight || document.documentElement.scrollHeight)){
              count+= 400;
              t = setTimeout(scrolldown, 1000);
            }else{
              callback((document.body.scrollHeight || document.documentElement.scrollHeight));
            }
        }, 1000);"""
        )
Faizan AlHassan
  • 389
  • 4
  • 8