url = 'https://www.youtube.com/'
driver = wb.Chrome()
driver.get(url)
# 스크롤 제어
body = driver.find_element_by_css_selector('body')
# 스크롤바 10번 내리기
for i in range(10):
body.send_keys(Keys.PAGE_DOWN)
time.sleep(0.1)
soup = bs(driver.page_source, 'lxml')
# 제목 데이터 가져오기
title = soup.select('a#video-title')
# 조회수 데이터 가져오기
view = soup.select('span.ytd-grid-video-renderer:nth-child(1)')
title_list = []
view_list = []
rank_list = []
# 리스트 안에 데이터값 집어넣기
for i in range(len(title)):
title_list.append(title[i].text.strip())
view_list.append(view[i].text.strip())
rank_list.append(i+1)
dic = {'제목' : title_list, '조회수' : view_list, '번호' : rank_list}
df = pd.DataFrame(dic)
df.set_index('번호', inplace = True)

dic 결과

df 결과
'Python > Crawling' 카테고리의 다른 글
[Crawling] 이미지 태그 수집 후 폴더 저장 (0) | 2022.06.09 |
---|---|
[Crawling] 지마켓 best 품목(상품명,가격,원산지) (0) | 2022.06.08 |
[Crawling] 한솥 제품설명 가져오기 (0) | 2022.05.25 |
[Crawling] 한솥 페이지 메뉴 가져오기 (0) | 2022.05.25 |
[Crawling] 구글 페이지(날씨 검색) (0) | 2022.05.19 |