Python
[selenium] move to bottom (scroll down)
bryan.oh
2023. 8. 3. 22:18
반응형
html = driver.find_element(By.TAG_NAME, 'html')
html.send_keys(Keys.END)
이렇게 하면 한번에 끝까지 내려감.
스크롤 한번씩 내리려면 아래와 같이
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
728x90
반응형