I’m struggling with extracting data from a specific webpage that contains a data table. The main issue is that I cannot scroll through the table to access all the records. The page itself doesn’t scroll normally like most websites.
I’ve attempted multiple approaches including JavaScript execution and ActionChains, but none seem to work. Even manual JavaScript commands in the browser console don’t produce the desired scrolling effect.
Here’s my current implementation:
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.service import Service
import time
def extract_table_data(page_url):
service = Service(executable_path='C:\\automation\\chromedriver.exe')
browser_options = webdriver.ChromeOptions()
browser = webdriver.Chrome(service=service, options=browser_options)
browser.maximize_window()
try:
browser.get(url=page_url)
time.sleep(8)
data_container = browser.find_element(By.XPATH, '//*[@id="dataGrid"]').send_keys(Keys.ARROW_DOWN)
ActionChains(browser).move_to_element(data_container).perform()
# Alternative attempts
# browser.execute_script("document.querySelector('#dataGrid').scrollTop = 400")
# grid_element = browser.find_element(By.XPATH, '//div[@id="mainWrapper"]')
# actions = ActionChains(browser)
# actions.move_to_element(grid_element).perform()
# browser.execute_script('window.scrollTo(0, 250)', grid_element)
except Exception as error:
print(error)
finally:
browser.close()
browser.quit()
def run_script():
extract_table_data("https://example-data-table.com/embed/view123")
if __name__ == "__main__":
run_script()
I also tried these JavaScript commands manually:
document.querySelector("#tableView").scrollTop=250
document.querySelector("#containerDiv").scrollTop=250
I believe the solution involves targeting the correct HTML element that controls the table’s internal scrolling mechanism, but I’m having trouble identifying it.