[오류] 파이썬 크롤링

ma·2023년 10월 22일
0

python

목록 보기
1/1
post-thumbnail

재생목록을 크롤링하던 중 발생한 문제

200개 이상의 영상들의 링크를 수집하지 못하고 100개까지 밖에 못함.

추측

  • 페이지를 내릴 때 생기는 로딩으로인해 끝까지 못함(100개 까지 표시되고 로딩됨)

시도1

  • 해당 페이지의 길이를 파악하여 스크롤한 다음 크롤링 실행!

그러나, 원래 쓰던 무한 스크롤 코드가 안 먹힘

시도2

  • 무한 높이가 아닌 웹사이트의 높이를 가져와서 해보자

웹의 높이 반환

scroll_pane_height = driver.execute_script('return document.documentElement.scrollHeight')

스크롤바 내리기

while True: # 높이만큼 스크롤 driver.execute_script('window.scrollTo(0,document.documentElement.scrollHeight)') 

# 화면 만들 때 까지 로딩

time.sleep(1) 

new_scroll_pane_height = driver.execute_script('return document.documentElement.scrollHeight') print(scroll_pane_height,new_scroll_pane_height) 

if scroll_pane_height == new_scroll_pane_height: 

    break scroll_pane_height = new_scroll_pane_height

profile
내가 공부하기 위해

0개의 댓글