Coding/Python
[Python] 셀레니움(Selenium) 페이지 스크롤 기능 만들기 !
포스트it
2022. 7. 1. 10:13
728x90
반응형
[Python] 셀레니움(Selenium) 페이지 스크롤 기능 만들기 !
코드로 바로 보시죠 !
# 스크롤 높이
last_height = driver.execute_script("return document.body.scrollHeight")
while True:
# 끝까지 스크롤
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
# 대기 1초 (로딩으로 인해 알맞는 초 조절)
time.sleep(1)
# 스크롤 길이 비교로 끝까지 갔는지 확인
new_height = driver.execute_script("return document.body.scrollHeight")
if new_height == last_height:
break
last_height = new_height
728x90
반응형