import requests as req
from bs4 import BeautifulSoup as bs
import pandas as pd
url = 'https://movie.naver.com/movie/sdb/rank/rmovie.nhn?sel=cur&date=20191228'
res = req.get(url)
#파서 종류 : lxml, html.parser, html5lib
soup = bs(res.content, 'lxml')
name = soup.select('div.tit5 > a')
rate = soup.find_all('td',class_='point')
len(name),len(rate)
#순위, 영화제목, 평점 수집
rank_list = []
name_list = []
rating_list = []
for index in range(len(name)):
rank = index+1
rank_list.append(rank)
name_list.append(name[index].text)
rating_list.append(rate[index].text)
#순위, 영화제목, 평점을 DataFrame으로 표현
movie_info = {'rank':rank_list, 'name':name_list, 'rate':rating_list}
movie = pd.DataFrame(movie_info)
movie.set_index('rank',inplace=True)
movie
#naver_movie_info.csv로 저장
movie.to_csv('naver_movie_info.csv', encoding='euc-kr')