Python Forum
How to Caputre Data After Selenium Scroll
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to Caputre Data After Selenium Scroll
#2
This is a better method to scroll to the bottom. It automatically identified the end of the page instead of arbitrary scrolling (and much faster too).
def scroll_to_bottom(driver):
    driver = self.browser
    SCROLL_PAUSE_TIME = 0.5
    # Get scroll height
    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(SCROLL_PAUSE_TIME)

        # 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
When you scroll down the page should load the html. But it can depend on the website. AFter you scroll to the bottom, you can then obtain driver.page_source
Recommended Tutorials:
Reply


Messages In This Thread
RE: How to Caputre Data After Selenium Scroll - by metulburr - Jul-30-2019, 09:07 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Selenium (Dropdown-) data Robin_at_Cantelli 2 6,220 Dec-29-2021, 03:16 AM
Last Post: ondreweil
  Scroll Down Post Instagram Likes rmiguelantunes74 0 3,169 Oct-05-2020, 07:38 PM
Last Post: rmiguelantunes74
  Extract data with Selenium and BeautifulSoup nestor 3 3,943 Jun-06-2020, 01:34 AM
Last Post: Larz60+
  Webelement scroll rove76 1 2,117 Mar-17-2020, 05:38 PM
Last Post: rove76
  Clicking on element not triggering event in Selenium Python (Event Key is not in data dkaeloredo 2 4,299 Feb-16-2020, 05:50 AM
Last Post: dkaeloredo
  Selenium get data from newly accessed page hoff1022 2 2,972 Oct-09-2019, 06:52 PM
Last Post: hoff1022
  Unable to access javaScript generated data with selenium and headless FireFox. pjn4 0 2,565 Aug-04-2019, 11:10 AM
Last Post: pjn4
  Can't get method to scroll down page. caarsonr 5 4,298 Jun-20-2019, 09:14 PM
Last Post: caarsonr
  Selenium Data Scrubbing - Need Some Help HalPlz 1 2,374 Feb-26-2018, 11:06 PM
Last Post: Larz60+
  Error in Selenium: CRITICAL:root:Selenium module is not installed...Exiting program. AcszE 1 3,653 Nov-03-2017, 08:41 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020