구글링을 하니 셀레니움으로 스크롤을 하는 방법을 찾는 글들이 많았다.
나도 인스타그램 글에 올려 두었으나, 다른 글들의 유입을 위해 따로 글로 써둔다.
혹시나 더 필요한 스크롤 방법이 있다면 추가해보겠다.
일반적으로 셀레니움에서의 스크롤은 자바스크립트를 이용해서 구현한다.
1. 원하는 높이 Y까지 스크롤
driver.execute_script("window.scrollTo(0, Y)")
2. 문서의 끝까지 1회 스크롤
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
3. 문서의 제일 끝까지 스크롤
SCROLL_PAUSE_TIME = 0.5
last_height = driver.execute_script("return document.body.scrollHeight")
while True:
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
time.sleep(SCROLL_PAUSE_TIME)
new_height = driver.execute_script()
new_height == last_height:
last_height = new_height
댓글을 불러오는 중...