파이썬 네이버티비 크롤링

yyyyy·2020년 4월 23일
0

혼공

목록 보기
1/5
import requests
from bs4 import BeautifulSoup
import openpyxl

wb = openpyxl.Workbook()
sheet = wb.active
sheet.append(["제목", "채널명", "재생수", "좋아요수"])

raw = requests.get("https://tv.naver.com/r/")
html = BeautifulSoup(raw.text, 'html.parser')

container = html.select("div.inner")

for cont in container:
    title = cont.select_one("dt.title").text.strip().replace(",", "")
    chn = cont.select_one("dd.chn").text.strip().replace(",", "")
    hit = cont.select_one("span.hit").text.strip().replace(",", "").replace("재생 수", "")
    like = cont.select_one("span.like").text.strip().replace(",", "").replace("좋아요 수", "")

    sheet.append([title, chn, hit, like])
    # 데이터를 구분해주기 위해 콤마

wb.save("test.xlsx")
profile
-스파르타코딩클럽 프로젝트

0개의 댓글